T.L*_*avy 6 segmentation-fault uiviewcontroller modalviewcontroller ios
我已经看过几次崩溃报告了.这是非常随机和罕见的,我无法理解.我所做的就是使用以下代码呈现模态视图控制器
ComposeController *newcontrol = [[ComposeController alloc]initWithMode:1 withNIB:@"ComposeController"];
newcontrol.delegate = self;
UINavigationController *holder = [[UINavigationController alloc] initWithRootViewController:newcontrol];
[self presentViewController:holder animated:YES completion:NULL];
Run Code Online (Sandbox Code Playgroud)
不知怎的,这导致了这完全随机:
OS Version: iPhone OS 6.1 (10B143)
Report Version: 104
Exception Type: SIGSEGV
Exception Codes: SEGV_ACCERR at 0x9
Crashed Thread: 0
Thread 0 Crashed:
0 libobjc.A.dylib 0x3b25c5d0 objc_msgSend + 16
1 CoreFoundation 0x334ba73f -[__NSPlaceholderArray initWithObjects:count:] + 271
2 CoreFoundation 0x334bae09 +[NSArray arrayWithObject:] + 45
3 UIKit 0x353e80ab -[UIWindow _rotationViewControllers] + 51
4 UIKit 0x353e7fe3 -[UIViewController viewControllerForRotation] + 91
5 UIKit 0x353e7f39 -[UIViewController _visibleView] + 97
6 UIKit 0x3546c05b -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 2483
7 UIKit 0x3546afab -[UIViewController presentViewController:withTransition:completion:] + 3399
8 MyApp 0x00046e97 -[Inbox composeHit] (Inbox.m:207)
Run Code Online (Sandbox Code Playgroud)
我一直都遇到相同的问题。这似乎是由于我从弹出窗口中呈现了一个模式视图控制器而造成的,该控制器未经充分测试并触发了Apple代码中的错误。问题在于,UIKit保留了对我的View Controller的未保留引用,该引用已经被取消并释放了,因此在以后的引用被击中。我的解决方法是避免显示来自弹出窗口的模式VC,或者自己无限期保留所有此类VC(在成员变量或某些此类变量中)。
以下是血腥的细节。
这是我用来触发问题的代码。
-(void) handlePinchFromCell:(AMPSupportingPhotoCell*) cell
{
UIViewController * vc = [[UIViewController alloc] init]; // UIViewController #0
[self presentViewController:vc animated:YES completion:nil];
[self performSelector:@selector(dismiss:) withObject:vc afterDelay:2];
}
-(void) dismiss:(UIViewController*)vc
{
[self dismissViewControllerAnimated:YES completion:^(){NSLog(@"-------");}];
}
Run Code Online (Sandbox Code Playgroud)
此代码是UIViewController#1的一部分,位于UIPopoverController内部,并从另一个UIViewController#2弹出,而UIViewController#2本身又是另一个视图UIViewController#3呈现的。崩溃发生在关闭弹出窗口,关闭控制器#2 ID之后。
如果启用“僵尸”,则得到相同的堆栈跟踪,但显示一条消息:
2013-03-13 20:04:24.681 Mercury[16698:19d03] handlePinchFromCell: a225710
2013-03-13 20:04:27.083 Mercury[16698:19d03] -------
2013-03-13 20:04:31.606 Mercury[16698:19d03] *** -[UIViewController retain]: message sent to deallocated instance 0xa225710
Run Code Online (Sandbox Code Playgroud)
因此,请注意,VC#0已分配,提交,在2秒后被解散,重新分配,但是在Apple的代码中仍然有悬挂的引用。当弹出窗口关闭且VC#2被关闭时,尝试访问已释放的VC时整个程序崩溃了。我相当确定这是Apple的错误。我还猜想这与从弹出窗口中显示VC有关,因此,如果您远离该窗口或自己保留VC,应该没问题。
另一个针对相同问题的堆栈跟踪信息是这样的。如果上面的代码运行两次,则会发生这种情况:
2013-03-13 20:12:53.883 Mercury[16735:19d03] handlePinchFromCell: 16d54da0
2013-03-13 20:12:56.285 Mercury[16735:19d03] -------
2013-03-13 20:13:03.481 Mercury[16735:19d03] handlePinchFromCell: a2565f0
2013-03-13 20:13:03.481 Mercury[16735:19d03] *** -[UIViewController isKindOfClass:]: message sent to deallocated instance 0x16d54da0
(lldb) bt
* thread #1: tid = 0x1f03, 0x017f8a97 CoreFoundation`___forwarding___ + 295, stop reason = EXC_BREAKPOINT (code=EXC_I386_BPT, subcode=0x0)
frame #0: 0x017f8a97 CoreFoundation`___forwarding___ + 295
frame #1: 0x017f894e CoreFoundation`_CF_forwarding_prep_0 + 14
frame #2: 0x00c42f90 UIKit`-[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:] + 907
frame #3: 0x00a40ee3 UIKit`-[UIViewController presentViewController:withTransition:completion:] + 4521
frame #4: 0x00a41167 UIKit`-[UIViewController presentViewController:animated:completion:] + 112
frame #5: 0x0006c32d Mercury`-[AMPSupportingPhotosViewController handlePinchFromCell:](self=0x16d55360, _cmd=0x0007a64a, cell=0x0a22a2a0) + 205 at AMPSupportingPhotosViewController.m:184
frame #6: 0x015336b0 libobjc.A.dylib`-[NSObject performSelector:withObject:] + 70
frame #7: 0x0006f317 Mercury`-[AMPSupportingPhotoCell handlePinch:](self=0x0a22a2a0, _cmd=0x00efb0db, sender=0x0a2504a0) + 215 at AMPSupportingPhotoCell.m:53
frame #8: 0x00c2185a UIKit`_UIGestureRecognizerSendActions + 139
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2036 次 |
| 最近记录: |