2013-01-11 69 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