UIActionSheet 访问错误,UIPresentationController 僵尸
Posted
技术标签:
【中文标题】UIActionSheet 访问错误,UIPresentationController 僵尸【英文标题】:UIActionSheet bad access, UIPresentationController zombie 【发布时间】:2014-07-05 05:31:04 【问题描述】:在 ios 8 中测试应用时,ActionSheet 因访问不当而不断崩溃。 (Xcode 6 beta 2,iOS 8 模拟器)
这里有一个相关的帖子:UIActionSheet crash in iOS8beta
仪器确实捕获了与UIPresentationController
相关的僵尸。我不确定我的阅读是否正确,但保留计数似乎从 6 下降到 -1。
这是完整的日志:
Event Type ∆ RefCt RefCt Timestamp Responsible Library Responsible Caller
0 Malloc +1 1 00:14.487.023 UIKit UINibDecoderDecodeObjectForValue
1 Retain +1 2 00:14.493.979 UIKit -[UIRuntimeConnection initWithCoder:]
2 Retain +1 3 00:14.494.009 UIKit -[UIRuntimeConnection initWithCoder:]
3 Retain +1 4 00:14.494.069 UIKit UINibDecoderDecodeObjectForValue
4 Retain +1 5 00:14.494.089 UIKit UINibDecoderDecodeObjectForValue
5 Retain +1 6 00:14.494.190 Foundation _NSSetUsingKeyValueSetter
6 Retain +1 7 00:14.494.257 UIKit -[UINib instantiateWithOwner:options:]
7 Release -1 6 00:14.494.395 UIKit -[UIRuntimeConnection dealloc]
8 Release -1 5 00:14.494.414 UIKit -[UIRuntimeConnection dealloc]
Release (2) -2 00:14.494.435 UIKit -[UINibDecoder finishDecoding]
10 Release -1 3 00:14.494.458 UIKit -[UINibDecoder finishDecoding]
12 Retain +1 3 00:14.496.105 Vit Calc -[RBCViewController actionSheet:clickedButtonAtIndex:]
Retain/Release (2) 00:14.496.275 UIKit -[_UIFullscreenPresentationController _setPresentedViewController:]
14 Retain +1 5 00:14.510.866 UIKit -[UIViewController setChildModalViewController:]
15 Retain +1 6 00:14.510.886 UIKit -[UIApplication _addViewControllerForLockingStatusBarTintColor:]
Retain/Release (2) 00:14.511.042 UIKit -[UIPresentationController runTransitionForCurrentState]
17 Retain +1 8 00:14.511.112 libsystem_sim_blocks.dylib _Block_object_assign
18 Retain +1 9 00:14.511.135 libsystem_sim_blocks.dylib _Block_object_assign
19 Release -1 8 00:14.511.152 UIKit -[UIActionSheet _indexTapped:]
20 Release -1 7 00:14.514.081 GraphicsServices GSEventRunModal
21 Release -1 6 00:14.514.098 UIKit -[UIStoryboardScene dealloc]
22 Retain +1 7 00:14.556.304 UIKit -[UIPeripheralHost(UIKitInternal) _beginPinningInputViewsOnBehalfOfResponder:]
23 Retain +1 8 00:14.564.411 UIKit -[UIViewController _setPresentedStatusBarViewController:]
24 Release -1 7 00:14.564.660 UIKit __destroy_helper_block_1444
25 Release -1 6 00:14.564.715 UIKit -[UIPeripheralHost(UIKitInternal) _stopPinningInputViewsOnBehalfOfResponder:]
26 Release -1 5 00:14.564.721 UIKit __destroy_helper_block_382
Retain/Release (2) 00:14.581.427 Foundation +[NSConcreteNotification newTempNotificationWithName:object:userInfo:]
Retain/Release (2) 00:14.595.199 Foundation +[NSConcreteNotification newTempNotificationWithName:object:userInfo:]
Retain/Release (4) 00:14.607.299 UIKit -[UIResponder becomeFirstResponder]
34 Retain +1 5 00:16.014.292 UIKit -[UIViewController _dismissViewControllerWithAnimationController:interactionController:completion:]
Retain/Release (2) 00:16.014.324 UIKit -[UIPresentationController runTransitionForCurrentState]
36 Retain +1 7 00:16.014.399 libsystem_sim_blocks.dylib _Block_object_assign
37 Release -1 6 00:16.014.430 UIKit -[UIViewController _dismissViewControllerWithAnimationController:interactionController:completion:]
38 Release -1 5 00:16.036.310 UIKit -[UIViewController _setPresentedStatusBarViewController:]
39 Release -1 4 00:16.036.802 UIKit __destroy_helper_block_382
42 Retain +1 5 00:16.546.187 UIKit -[UIViewController _didFinishDismissTransition]
43 Retain +1 6 00:16.546.190 UIKit -[UIApplication _removeViewControllerForLockingStatusBarTintColor:]
44 Release -1 5 00:16.546.190 UIKit -[UIApplication _removeViewControllerForLockingStatusBarTintColor:]
45 Release -1 4 00:16.546.191 UIKit -[UIApplication _removeViewControllerForLockingStatusBarTintColor:]
46 Release -1 3 00:16.546.192 UIKit -[UIViewController setChildModalViewController:]
47 Release -1 2 00:16.546.195 UIKit -[UIViewController _didFinishDismissTransition]
50 Zombie -1 00:18.518.590 UIKit -[UIPresentationController runTransitionForCurrentState]
50 Zombie -1 00:18.518.590 UIKit -[UIPresentationController runTransitionForCurrentState]
短版(过滤)
Event Type ∆ RefCt RefCt Timestamp Responsible Library Responsible Caller
Retain/Release (2) 00:14.496.275 UIKit -[_UIFullscreenPresentationController _setPresentedViewController:]
1 Retain +1 7 00:14.511.042 UIKit -[UIPresentationController runTransitionForCurrentState]
2 Retain +1 8 00:14.564.411 UIKit -[UIViewController _setPresentedStatusBarViewController:]
3 Retain +1 6 00:16.014.324 UIKit -[UIPresentationController runTransitionForCurrentState]
4 Release -1 5 00:16.036.310 UIKit -[UIViewController _setPresentedStatusBarViewController:]
6 Zombie -1 00:18.518.590 UIKit -[UIPresentationController runTransitionForCurrentState]
在简短的版本中,似乎 Retain 实际上做了相反的事情:
1 Retain +1 7 00:14.511.042 UIKit -[UIPresentationController runTransitionForCurrentState]
3 Retain +1 6 00:16.014.324 UIKit -[UIPresentationController runTransitionForCurrentState]
我试图在一个新项目中重现这一点,但没有成功。
另外,似乎只在我的 UIActionSheet 委托设置(自我)时发生。
此时,我只想向 Apple 发送一份更简洁的错误报告,所以我只是想找出问题所在。
更新
可以复制。
当UIActionSheet
是在一个单独的方法中初始化时,就会发生这种情况。 并且它的委托正在呈现另一个 ViewController。
例如:
@implementation RBCViewController
UIActionSheet *actionSheet;
- (void)viewDidLoad
[super viewDidLoad];
[self createActionSheet];
- (void)createActionSheet
actionSheet = [[UIActionSheet alloc]init];
- (IBAction)showActionSheet:(UIButton *)sender
// Add buttons, assign delegate here
[actionSheet showInView:self.view];
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
// Present another ViewContoller here.
// This will fail with 'Bad Access' on the second time
【问题讨论】:
beta 3 是否发生同样的情况 @Dont_Peep 是的。我没有费心提及它,但我使用的是 Xcode 6 Beta 3。我向 Apple 报告并被要求提供更多信息,我更新了这些信息。我花了一些时间把它从一个大项目中分离出来。 【参考方案1】:我有同样的问题。解决方案是在每次使用后释放你的 UIActionSheet,因为它会保留它用来呈现自身的 UIWindow(它有一个指向你呈现的模态 VC 的 unsafe_unretained 指针)。
未来的读者:当心,iOS8 发布后可能不再适用。
【讨论】:
好电话!我们必须密切关注即将发生的变化。以上是关于UIActionSheet 访问错误,UIPresentationController 僵尸的主要内容,如果未能解决你的问题,请参考以下文章