ios - 将 Cancel UIButton 添加到导航 Controller

标签 ios cocoa-touch uinavigationcontroller

我正在使用 Storyboard,我向 View Controller 添加了一个导航栏,并向导航栏添加了两个栏按钮(在 Storyboard中而不是代码中),一个是“保存”按钮,另一个是“取消”按钮。

现在我希望当我按下取消按钮时,已查看的 Controller 消失并显示上一个 View Controller 。我应该在取消按钮的操作方法中包含什么代码:

- (IBAction)cancel:(id)sender 
{
    // what code should be written here ?
}

最佳答案

这取决于您最初如何呈现 View Controller 。如果您以模态方式呈现它,那么您将使用以下内容:

[self dismissViewControllerAnimated:YES completion:nil];

但是,如果您通过导航 Controller 推送到当前 View Controller ,那么您将使用此:

[self.navigationController popViewControllerAnimated:YES];

关于ios - 将 Cancel UIButton 添加到导航 Controller ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18261738/

相关文章:

ios - iPad 在使用 Xamarin.Forms 启动时崩溃

ios - 类型 'URL' 没有成员 'fileURL' - Swift 3

iphone - 刷新 UITableView

ios - 将 UINavigationView 的大小限制为其当前呈现的 Controller 的大小?

ios - 为什么导航 Controller 在 - (BOOL)shouldPerformSegueWithIdentifier : is implemented? 时不工作

ios - 在单元测试中手动向左滑动以调用处理程序以在 Swift 中进行测试

ios - 缺少所需图标问题和找不到营销图标问题

cocoa-touch - 第二个 UIWindow 不显示 (iPad)

iOS 5.1 UIView调用 super ViewController的选择器

ios - 如何检测是否从导航 Controller 弹出 View Controller ?