1

我想解決如何讓我的名爲「home」的UIBarButtonItem返回到我的第一個初始ViewController如何設置一個UIBarButtonItem觸發ios中的動作

我已經實現了我的ViewControllerSecondviewDidLoad我的按鈕:

@property (nonatomic, weak) UIBarButtonItem *homeProperty; 

// Create a home button 
UIBarButtonItem *homeButton = [[UIBarButtonItem alloc] initWithTitle:@"Home" style:UIBarButtonItemStylePlain target:self action:@selector(homeProperty)]; 
[self.navigationItem setLeftBarButtonItem:homeButton animated:NO]; 

我需要爲此創造一個IBAction爲方法?此外,在正確的方法viewDidLoad

所以,總結我需要能夠從ViewControllerSecond回到ViewController實施UIBarButtonItem,但我無法弄清楚如何做到這一點。

非常感謝

回答

1

你是如何加入第二視圖控制器到第一?您是否撥打pushViewControllerpresentModalViewController?如果您使用的是UINavigationController,則調用pushViewController應自動在導航欄上爲您創建後退按鈕。使用Master-Detail應用程序在XCode中創建一個新項目,請參閱UINavigationController應該如何工作的示例。

+0

對不起,我的第一個'ViewController'沒有嵌套在'UINavigationController'中。我使用round rect按鈕並創建一個新的'UINavigationController'和'ViewControllerSecond'實例,然後使用:'[self presentViewController:detailNav animated:YES completion:nil];''ViewControllerSecond'; – user1574598

相關問題