2012-01-17 115 views
2

以下的UIAlertViewDelegate协议规定:UIAlertView中的委托方法alertViewCancel:不会被调用

// Called when we cancel a view (eg. the user clicks the Home button). This is not called when the user clicks the cancel button. 
// If not defined in the delegate, we simulate a click in the cancel button 
- (void)alertViewCancel:(UIAlertView *)alertView; 

不过,我有一个显示UIAlertView,当我打到现在在模拟器主页按钮,该方法alertViewCancel:不会被调用。请注意,当我触摸AlertView上的一个按钮时,alertView:clickedButtonAtIndex:委托方法会被调用,以便代理正确连接。

这是苹果方面的缺陷,还是我,或者是模拟器?

编辑:

我目前通过听取UIApplicationWillResignActiveNotification通知,我做以下驳回AlertView解决此问题:

[self.currentAlert dismissWithClickedButtonIndex:-1 animated:NO]; 
[self.currentAlert release]; 
self.currentAlert = nil; 
+0

你正在做点clickButtonAtIndex会覆盖alertViewCancel的任何调用吗? – carbonbasednerd 2012-01-17 13:43:08

+0

您可以显示创建警报视图的代码吗? – rishi 2012-01-17 13:43:40

+0

@carbonbasednerd好问题,但是当我点击HOME按钮时,alertView:clickedButtonAtIndex:方法不会被调用。我通过听'UIApplicationWillResignActiveNotification'通知来解决这个问题(我用这一点信息更新了我的帖子) – Besi 2012-01-17 13:47:43

回答

3

它被调用时,系统实际上CANCEL请求您的警报视图。当应用程序进入后台时,您的警报视图不会被取消,除非您的应用程序被flotsam进程驱逐,当您再次成为前台时,警报视图将再次弹出。我认为,虽然我不太确定,但如果flotsam会杀死你的程序,你将会得到这个代表电话作为拆解序列的一部分。

在这一点上,文档可能有点误导。它曾经是主页按钮按下取消警报的情况,但情况并非总是如此。

+0

好吧,我想我明白了。这意味着在“预先多任务设备”中,该方法可能会被调用,因为'UIAlertView'确实会被取消,因此不会再显示。但是这个“flotsam”是谁? :-) – Besi 2012-01-17 14:15:06

+1

flotsam是当系统需要更多内存时应用程序的系统进程。当设备上的内存压力很高时,flotsam会选取一个后台应用程序,并发送内存警告。如果应用程序没有释放足够的内存,flotsam会将其关闭。 “看门狗”是一种杀死不响应应用程序的系统进程,这是一种亲密的精神。这个名字是“flotsam and jetsam”中的一个双关语,用于浮动的东西并没有被使用。 – 2012-01-17 14:19:54

+0

+1:感谢您的洞察! – Besi 2012-01-17 14:39:10

相关问题