UIActionSheet访问不良,UIPresentationController僵尸 [英] UIActionSheet bad access, UIPresentationController zombie
问题描述
在iOS 8中测试应用程序时,ActionSheet会因访问不良而崩溃。 (Xcode 6 beta 2,iOS 8模拟器)
此处有相关帖子: iOS8beta中的UIActionSheet崩溃
乐器捕获与 UIPresentationController相关的僵尸
。我不确定我是否正确阅读它,但似乎保留计数从6下降到-1。
这是完整的日志:
事件类型ΔRefCtRefCt时间戳负责图书馆负责人来电
0 Malloc +1 1 00:14.487.023 UIKit UINibDecoderDecodeObjectForValue
1保留+1 2 00:14.493.979 UIKit - [UIRuntimeConnection initWithCoder:]
2保留+1 3 00:14.494.009 UIKit - [UIRuntimeConnection initWithCoder:]
3保留+1 4 00:14.494。 069 UIKit UINibDecoderDecodeObjectForValue
4保留+1 5 00:14.494.089 UIKit UINibDecoderDecodeObjectForValue
5保留+1 6 00:14.494.190基础_NSSetUsingKeyValueSetter
6保留+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]
R elease(2)-2 00:14.494.435 UIKit - [UINibDecoder finishDecoding]
10发布-1 3 00:14.494.458 UIKit - [UINibDecoder finishDecoding]
12保留+1 3 00:14.496。 105 Vit Calc - [RBCViewController actionSheet:clickedButtonAtIndex:]
保留/释放(2)00:14.496.275 UIKit - [_ UIFullscreenPresentationController _setPresentedViewController:]
14保留+1 5 00:14.510.866 UIKit - [ UIViewController setChildModalViewController:]
15保留+1 6 00:14.510.886 UIKit - [UIApplication _addViewControllerForLockingStatusBarTintColor:]
保留/释放(2)00:14.511.042 UIKit - [UIPresentationController runTransitionForCurrentState]
17保留+1 8 00:14.511.112 libsystem_sim_blocks.dylib _Block_object_assign
18保留+1 9 00:14.511.135 libsystem_sim_blocks.dylib _Block_object_assign
19版本-1 8 00:14.511.152 UIKit - [UIActionSheet _indexTapped:]
20发布-1 7 00:14.514.081 GraphicsServices GSEventRunModal
21发布-1 6 00:14.514.098 UIKit - [UIStoryboardScene dealloc]
22保留+1 7 00:14.556.304 UIKit - [UIPeripheralHost(UIKitInternal)_beginPinningInputViewsOnBehalfOfResponder :]
23保留+1 8 00:14.564.411 UIKit - [UIViewController _setPresentedStatusBarViewController:]
24版本-1 7 00:14.564.660 UIKit __destroy_helper_block_1444
25版本-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:对象:userInfo:]
保留/释放(2)00:14.595.199基础+ [NSConcreteNotification newTempNotificationWithName:object:userInfo:]
保留/释放(4)00:14.607.299 UIKit - [UIResponder是comeFirstResponder]
34保留+1 5 00:16.014.292 UIKit - [UIViewController _dismissViewControllerWithAnimationController:interactionController:completion:]
保留/释放(2)00:16.014.324 UIKit - [UIPresentationController runTransitionForCurrentState]
36保留+1 7 00:16.014.399 libsystem_sim_blocks.dylib _Block_object_assign
37发布-1 6 00:16.014.430 UIKit - [UIViewController _dismissViewControllerWithAnimationController:interactionController:completion:]
38发布-1 5 00:16.036.310 UIKit - [UIViewController _setPresentedStatusBarViewController:]
39发布-1 4 00:16.036.802 UIKit __destroy_helper_block_382
42保留+1 5 00:16.546.187 UIKit - [UIViewController _didFinishDismissTransition]
43保留+1 6 00:16.546.190 UIKit - [UIApplication _removeViewControllerForLockingStatusBarTintColor:]
44发布-1 5 00:16.546.190 UIKit - [UIApplication _removeViewC ontrollerForLockingStatusBarTintColor:]
45 Release -1 4 00:16.546.191 UIKit - [UIApplication _removeViewControllerForLockingStatusBarTintColor:]
46 Release -1 3 00:16.546.192 UIKit - [UIViewController setChildModalViewController:]
47发布-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]
短版(已过滤)
事件类型ΔRefCtRefCt时间戳负责图书馆负责人来电
保留/释放(2)00:14.496.275 UIKit - [_ UIFullscreenPresentationController _setPresentedViewController:]
1保留+1 7 00:14.511.042 UIKit - [UIPresentationController runTransitionFo rCurrentState]
2保留+1 8 00:14.564.411 UIKit - [UIViewController _setPresentedStatusBarViewController:]
3保留+1 6 00:16.014.324 UIKit - [UIPresentationController runTransitionForCurrentState]
4发布 - 1 5 00:16.036.310 UIKit - [UIViewController _setPresentedStatusBarViewController:]
6 Zombie -1 00:18.518.590 UIKit - [UIPresentationController runTransitionForCurrentState]
在短版本中,似乎Retain实际上正好相反:
1保留+1 7 00:14.511.042 UIKit - [UIPresentationController runTransitionForCurrentState]
3保留+1 6 00:16.014.324 UIKit - [UIPresentationController runTransitionForCurrentState]
我试图在一个新项目中重现这个,但不能。
此外,似乎只会发生当我的UIActionSheet委托设置(自己)时。
此时,我是st想要向Apple发送更简洁的错误报告,所以我只想确定问题。
更新
可以重现。
当 UIActionSheet
在一个单独的方法中初始化时,会发生这种情况。 AND 其代表正在展示另一个ViewController。
为了exapmle:
@implementation RBCViewController
{
UIActionSheet * actionSheet;
}
- (void)viewDidLoad
{
[super viewDidLoad];
[self createActionSheet];
}
- (void)createActionSheet
{
actionSheet = [[UIActionSheet alloc] init];
}
- (IBAction)showActionSheet:(UIButton *)发件人{
//添加按钮,在此指派代表
[ actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
//在这里展示另一个ViewContoller。
//这将在第二次错误访问时失败
}
我有同样的问题。解决方案是在每次使用后释放你的UIActionSheet,因为它会保存在它用来呈现的UIWindow上(它有一个unsafe_unretained指向你提供的模态VC)。
<未来的读者:注意,当iOS8发布时,这可能不再适用。
Testing an app in iOS 8, ActionSheet keeps crashing with bad access. (Xcode 6 beta 2, iOS 8 simulator)
There is a related post here: UIActionSheet crash in iOS8beta
Instruments do catch a zombie related to UIPresentationController
. I'm not sure I'm reading it correctly, but it seems that retain count drops from 6 to -1.
Here's the full log:
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]
Short Version (filtered)
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]
On short version, it seems that Retain actually do the opposite:
1 Retain +1 7 00:14.511.042 UIKit -[UIPresentationController runTransitionForCurrentState]
3 Retain +1 6 00:16.014.324 UIKit -[UIPresentationController runTransitionForCurrentState]
I tried to reproduce this in a new project, but couldn't.
Also, seems to only happens when my UIActionSheet delegate is set (to self).
At this point, I just want to send Apple a more concise bug report, so I'm just trying to pinpoint the issue.
UPDATE
Can reproduce.
This happens when UIActionSheet
is initialized in a separate method than the one presenting it. AND its delegate is presenting another ViewController.
For exapmle:
@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
}
I had the same issue. The solution is to release your UIActionSheet after every use, since it will hold on the UIWindow it used to present itself (which has a unsafe_unretained pointer to the modal VC you presented).
Future readers: beware, this might no longer be true when iOS8 is released.
这篇关于UIActionSheet访问不良,UIPresentationController僵尸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!