阻止导航控制器进行导航并要求用户确认

发布于 2024-11-15 04:17:43 字数 211 浏览 2 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

乱世争霸 2024-11-22 04:17:43

您不能创建一个 UIBarButtonItem 实例并将其分配给视图控制器的导航项吗?像这样,

UIBarButtonItem * backButton = [[[UIBarButtonItem alloc] initWithTitle:@"Back" 
                                                                 style:UIBarButtonItemStyleBordered
                                                                target:self
                                                                action:@selector(backButtonPressed:)] autorelease];
self.navigationItem.leftBarButtonItem = backButton;

然后在 backButtonPressed: 中触发警报视图。

- (void)backButtonPressed:(id)sender {
    // Trigger an alert view.
}

根据用户的选择,您可以弹出视图控制器或不弹出视图控制器。

Can't you create a UIBarButtonItem instance and assign it to the view controller's navigation item? Something like this,

UIBarButtonItem * backButton = [[[UIBarButtonItem alloc] initWithTitle:@"Back" 
                                                                 style:UIBarButtonItemStyleBordered
                                                                target:self
                                                                action:@selector(backButtonPressed:)] autorelease];
self.navigationItem.leftBarButtonItem = backButton;

and then in backButtonPressed:, trigger an alert view.

- (void)backButtonPressed:(id)sender {
    // Trigger an alert view.
}

Based on the user choice, you can pop the view controller or not.

悲歌长辞 2024-11-22 04:17:43

返回用户的按钮是 IBAction (或者它是您在以编程方式设置按钮时定义的方法),因此您可以添加来自 here 进入 IBAction 并输入要返回的代码 在

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

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

- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文