2012-08-13 38 views
0

我在導航欄的左側創建了一個信息按鈕。 如何讓用戶在點擊信息按鈕後導航到另一個名爲「AboutViewController」的視圖? 請幫忙!! (下面是我的代碼)導航信息按鈕到另一個屏幕Xcode

UIButton* infoButton = [UIButton buttonWithType:UIButtonTypeInfoLight]; 
[infoButton addTarget:self action:@selector(viewWillAppear:) forControlEvents:UIControlEventTouchUpInside]; 
UIBarButtonItem *modalButton = [[UIBarButtonItem alloc] initWithCustomView:infoButton]; 
[self.navigationItem setLeftBarButtonItem:modalButton animated:YES]; 
[modalButton release]; 

回答

0

我想的第一件事要告訴你,另一個合適的名稱更改@selector方法就像在這種情況下,我已經給navigateToAboutView:。因爲您在代碼中給出的方法名稱可能出現在您要調用的相同視圖中!

現在寫了下面的代碼在你自定義的方法 -

- (void) navigateToAboutView:(id)sender 
{ 
    AboutViewController *aboutViewCntrl =[[AboutViewController alloc]initWithNibName:@"AboutViewController" bundle:nil]; 
    [self.navigationController pushViewController:aboutViewCntrl animated:YES]; 
} 
0

我不知道爲什麼你已經通過viewWillAppear:作爲選擇,當你添加一個目標按鈕,而是選擇定義哪種方法當按鈕被點擊時調用。 viewWillAppear:是每次視圖即將顯示時調用的方法,因此在輕按按鈕時調用它是沒有意義的。因此,它更改爲類似openAnotherView,創建這樣一個方法:如果你想解僱有關視圖控制器,然後使用此行AboutViewController

- (void)openAnotherView { 
    // Instantiate the view controller. 
    AboutViewController *aboutViewController = [[AboutViewController alloc] init]; // or initWithNibName:bundle: if you use Interface Builder. 

    // Present the view controller modally. 
    [self presentModalViewController:aboutViewController animated:YES] 
} 

[self dismissModalViewControllerAnimated:YES] 
相關問題