- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
当用户按下我的 UINavigationController View 上的后退按钮时,我想显示一个带有 2 个选项的 UIAlertView。一个选项 (OK) 允许用户返回(到上一个屏幕),另一个选项 (Cancel) 将留在当前 Controller 。
我在我的 viewWillDisappear 中实现了以下代码(我在这里找到的):
-(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:@"All Data will be lost"
message:@"You must be connected to the internet to use this app."
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
alert.tag = 1;
[alert show];
[alert release];
}
[super viewWillDisappear:animated];
}
问题是,在我按下“返回”后, View 立即跳转到上一个屏幕,并在此屏幕上显示 UIAlertView。
在 UIAlertView 回调方法中,我使用了以下编码,但没有任何反应(我认为这是因为我已经在之前的 View 中看到过这一点):
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
if(buttonIndex == 1)
NSLog(@"back");
//Go Back ...
}
BR,迈贝克
最佳答案
当 viewWillDisappear
被调用时,为时已晚。导航 Controller 已经关闭了 View Controller 。
相反,您需要拦截后退按钮触摸事件。您可以通过多种方式执行此操作 - 您可以有一个自定义后退按钮,它显示您的 UIAlertView
。或者您可以使用 UINavigationBarDelegate
,它有一个 navigationBar:shouldPopItem:
方法。
关于objective-c - UIAlertView 在 viewWillDisappear 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8383463/
这个问题已经有答案了: iOS How to dismiss UIAlertView with one tap anywhere? (2 个回答) 已关闭10 年前。 嗨,我是 Xcode 新手,ob
我试图在我的 swift 应用程序中显示一个 UIAlertView alert = UIAlertView(title: "", message: "bla",
问题是 iOS 键盘有时不再有反应。所以没有输入是可能的。如果我取消注释 clickedButtonAtIndex 中的第二个 UIAlertView,它工作正常。 原因可能在其他地方?我不知道...
我是 iPhone 开发人员的新人, 我想依次实现2个警报 View ,就像当用户按下删除按钮时,第一个警报 View 会询问你确定要删除吗?有两个按钮是 和否 现在,如果用户按 yes ,则第二个警
我想弄清楚为什么我的应用程序会崩溃。 它在带有 ios5.1 的模拟器中运行的 Xcode 4.4 中运行良好,但是当我切换到 xcode 4.5 和 ios6 时,我得到了 EXC_BAD_ACCE
我的 iOS 应用程序正在使用 Swift 2.0、RMUniversalAlert 版本 0.7 和 UIAlertView+Blocks 版本 0.9 当我在 Xcode 7 中构建它时,出现错误
我遇到了崩溃: *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-
我在主线程上显示 UIAlertView 时遇到问题。我不知道为什么,但它不断崩溃,尽管我在主线程上运行。以下 block 位于后台线程上,但我在主线程上有警报,如下所示: void (^remove
我已将 iPhone 设置为横向模式,但当我尝试显示 UIAlertView 时,它会进入纵向模式。横向模式下如何显示? 最佳答案 在applicationDelegate.m文件的applicati
我使用 UIAlerView 子类创建自定义登录页面。现在,当我单击按钮时,它会打开 UIAlertView 我想根据按下的按钮更改主视图。 但是,由于 UIAlerView 的所有实现都在另一个类中
我弹出一个 UIAlertView 来询问用户是否确实要打开某个 URL。如果他们选择"is",我的应用程序会立即打开 URL 并发送到后台。当用户重新打开我的应用程序(使用多任务处理)时,警报 Vi
有没有办法将 .tag 添加到 UIAlertView 按钮?原因是,我向警报添加了一些动态按钮,这些按钮有时会出现在警报中,有时不会。我认为最好的方法是添加标签。有更好的方法吗? 警报中始终出现的选
我在 ib 中创建了一个自定义 uialertview,带有两个按钮和一个文本字段。然后我以这种方式创建一个 .h 和一个 .m: #import @interface DialogWelcome
看一下下面的代码,问题是AlertView没有显示出来,即使我在调试中看到代码已被执行。 请指教。 非常感谢 埃兰 -(void)displayABC:(id)sender { sta
我正在尝试更改 uialertview 的背景。一切工作正常,除了我添加到 uialert View 的背景图像不会在警报 View 内缩放。所以基本上你只能看到基于当前大小的背景图像的一部分。有什么
在我的应用程序中,我使用验证 key 通过 Wi-Fi 从服务器下载内容。如果许可证 key 错误或 wi-fi 不可用,我需要显示 UIAlert。我已经编写了用于显示警报 View 的男女混合代码
我创建了一个带有两个按钮和一个文本字段的 uialertview,如果文本字段为空,我希望禁用“确定”按钮。我如何获取 uibutton 对象来更改启用状态。 最佳答案 您可以使用从 UIContro
iPhone 应用程序开发人员您好, 我正在开发一个 iPhone 应用程序。该应用程序允许用户将图像上传到我的服务器。我想在alertView中显示上传进度。我需要一些示例代码来说明如何实现带有进度
有没有办法以编程方式隐藏 UIAlertView。我正在我的进度 View 中显示进度 View ,当进度 View = 1.0 时,我想隐藏 UIAlertView。 最佳答案 您可以做的是观察(使
这个问题已经有答案了: 已关闭10 年前。 Possible Duplicate: Is it possible to lay out 2 buttons vertically on UIAlertV
我是一名优秀的程序员,十分优秀!