如何以编程方式在UINavigationController中按“返回”button
我有一个名为FriendsViewController UINavigationController内的UIViewController 。 第二个叫做FriendsDetailedViewController UIViewController 。 从第一个视图控制器导航到第二个时,我想以编程方式在需要时按下“ Backbutton。 这个怎么做? 
简单的使用
 [self.navigationController popViewControllerAnimated:YES] 
从FriendsDetailedViewController。 您的视图将被popup,即后退button的行为
如果按“返回”button,则意味着只要转到上一个视图控制器,就可以调用:
 [self.navigationController popViewControllerAnimated:YES]; 
这是快捷的方法
 if let navController = self.navigationController { navController.popViewControllerAnimated(true) } 
1)当你在当前的NavigationControllerpopup然后
在Swift中
 self.navigationController?.popViewControllerAnimated(true) 
目标C
 [self.navigationController popViewControllerAnimated:YES]; 
2)当你退回另一个导航控制器然后
在Swift中
 let story = UIStoryboard(name: "Main", bundle: nil) let pushVC = story.instantiateViewControllerWithIdentifier("PushVC") let navigation = story.instantiateViewControllerWithIdentifier("homeNavigation") as! UINavigationController navigation.pushViewController(pushVC!, animated: true) 
在目标C中
 UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"storyBoardName" bundle:nil]; pushVC* ObjectOfPushVC = [storyboard instantiateViewControllerWithIdentifier:@"pushVC"]; [self.navigationController pushViewController:ObjectOfPushVC animated:YES]; 
这是我在Swift 3中做的
 _ = self.navigationController?.popViewController(animated: true) 
  _用于抑制由XCode生成的丑陋警告。