2013-01-11 71 views
2

我是一名学生,正在学习和为我的学校开发一款应用程序,我刚刚开始并且做得很好,但是我收到错误“Expected identifier or' “我已经花了几天的时间阅读帖子和谷歌,并没有解决方案,我发现正在为我工​​作预期的标识符或'(' - xCode

我想在我的应用程序的第二个选项卡上的圆形按钮链接到学校。网站

这里是.H:

#import <UIKit/UIKit.h> 

@interface SecondViewController : UIViewController { 

} 


- (IBAction)Website:(id)sender; 



@end 

这里是我的.m错误COM mented:

#import "SecondViewController.h" 

@interface SecondViewController() 

@end 

@implementation SecondViewController 

-(IBAction)Website { 
[[UIApplication sharedApplication ] openURL:[NSURL URLWithString:@"http://www.google.com"]]; 

} 


{  **// Error is on this line[23]** 
[super viewDidLoad]; 
// Do any additional setup after loading the view, typically from a nib. 
} 

- (void)didReceiveMemoryWarning 
{ 
[super didReceiveMemoryWarning]; 
// Dispose of any resources that can be recreated. 
} 


- (IBAction)Website; 


- (IBAction)Website:(id)sender; { 
} 
@end 

我该如何解决这个小家伙?非常感谢你! 此外,.h文件由xCode组成,通过简单地控制从按钮拖动到.h并创建一个动作。这可能是原因吗?

+0

你没有viewDidload方法! –

回答

2

我想你不小心删除这一行:

- (void)viewDidLoad 

这条线之上

{  **// Error is on this line[23]** 

但为了简单起见,你可以删除:

{  **// Error is on this line[23]** 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

因为你不使用viewDidLoad for anything

+0

在' - (void)viewDidLoad'中重新加入!它拉起了一个重复的错误,但只是删除' - (IBAction)网站; '固定的。非常感谢!我现在不知道何时或如何删除它。我把代码的其他部分留在那里,因为我不确定我以后会不会需要它。再次谢谢你。 – user1970606

+0

如果你不介意再次帮助。我的应用程序现在可以在模拟器中运行,但我的按钮不会为我做任何事情。它在模拟器中禁用?或者我有不正确的代码? – user1970606

+0

您需要在Xib或Storyboard中将您的按钮和IBAction方法“连线”(在助理编辑器中打开.m文件,以便您可以在Xib/Storyboard旁边看到它,然后您可以按住Ctrl键并从该方法的按钮)。如果你陷入困境,那么你应该在这里开一个新的问题来得到更详细的答案。 – foundry