阻止导航控制器进行导航并要求用户确认
我有一个 UITableViewController
,它使用 didSelectRowAtIndexPath:
使用 initWithNibName:
初始化视图控制器。用户能够返回表视图,但我想执行 if/else 并显示警报视图以确认用户是否想要返回表视图。我不知道从哪里开始。
简而言之,我想自定义后退按钮。
I have a UITableViewController
that uses didSelectRowAtIndexPath:
to init a view controller with initWithNibName:
. The user is able to return to the table view but I would like to perform a if/else and display an alert view to confirm if the user would like to return to the table view. I have no clues where to start.
In short, I would like to customize the back button.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不能创建一个
UIBarButtonItem
实例并将其分配给视图控制器的导航项吗?像这样,然后在
backButtonPressed:
中触发警报视图。根据用户的选择,您可以弹出视图控制器或不弹出视图控制器。
Can't you create a
UIBarButtonItem
instance and assign it to the view controller's navigation item? Something like this,and then in
backButtonPressed:
, trigger an alert view.Based on the user choice, you can pop the view controller or not.
返回用户的按钮是 IBAction (或者它是您在以编程方式设置按钮时定义的方法),因此您可以添加来自 here 进入 IBAction 并输入要返回的代码 在
The button that returns the user is an IBAction (or it's a method that you define when you set the button up programmatically), so you can add the code from here into the IBAction and put the code to return in