gpt4 book ai didi

ios - 防止 leftBarButtonItem 导航项显示警报

转载 作者:行者123 更新时间:2023-11-29 02:08:28 25 4
gpt4 key购买 nike

我有一个文本编辑 View ,我想在编辑文本后返回 Root View 之前提示用户。

到目前为止我已经尝试过了。

self.navigationItem.leftBarButtonItem.title = @"Back";
self.navigationItem.leftBarButtonItem.tintColor = [UIColor grayColor];


-(void) viewWillDisappear:(BOOL)animated {
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound) {
// back button was pressed. We know this is true because self is no longer
// in the navigation stack.
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Confirm Submission" message:@"Current Job Sheet Incomplete\n Please Confirm Your Submission" delegate:self cancelButtonTitle:@"Submit" otherButtonTitles:@"Cancel", nil];
alert.tag = 1;
[alert show];
}
// [super viewWillDisappear:animated];
}

虽然这会显示警报,但不会阻止用户被推送到 Root View 。

最佳答案

在 leftBarButton 上添加自定义按钮

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

-(void)navigationBackBtnTap{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Confirm Submission" message:@"Current Job Sheet Incomplete\n Please Confirm Your Submission" delegate:self cancelButtonTitle:@"Submit" otherButtonTitles:@"Cancel", nil];
alert.tag = 1;
[alert show];
}

关于ios - 防止 leftBarButtonItem 导航项显示警报,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29532319/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com