我已经解决了我的应用程序中的所有错误,除了这个偶尔出现的错误..
在我的视图控制器中,我有一个延迟加载图像的自定义图像下载器类。在我输入代码将mainDownloader.delegate设置为nil之前,如果我要去视图并在下载图像之前单击后退,它就会崩溃。但现在的问题是,它有时会在使用应用程序一段时间后崩溃并且在此行崩溃(第318行):
if(mainDownloader!=nil && mainDownloader.delegate !=nil)
这当然是在选择后退按钮并且正在卸载视图时发生的。
以下是完整的方法:
-(void) viewWillDisappear:(BOOL)animated
{
if ([self.navigationController.viewControllers indexOfObject:self]==NSNotFound)
{
if(mainDownloader!=nil && mainDownloader.delegate !=nil)
mainDownloader.delegate = nil;
}
[super viewWillDisappear:animated];
}
崩溃日志:
Crashed Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x34f5a88f __exceptionPreprocess + 163
1 libobjc.A.dylib 0x36f28259 objc_exception_throw + 33
2 CoreFoundation 0x34f5da9b -[NSObject doesNotRecognizeSelector:] + 175
3 CoreFoundation 0x34f5c915 ___forwarding___ + 301
4 CoreFoundation 0x34eb7650 _CF_forwarding_prep_0 + 48
5 MyApp 0x000268cd -[productSelected viewWillDisappear:] (productselected.m:318)
6 UIKit 0x3153bd3d -[UIViewController _setViewAppearState:isAnimating:] + 145
7 UIKit 0x31595a57 -[UIViewController beginAppearanceTransition:animated:] + 191
8 UIKit 0x3153ea81 -[UINavigationController _startTransition:fromViewController:toViewController:] + 781
9 UIKit 0x3153e6ab -[UINavigationController _startDeferredTransitionIfNeeded] + 251
10 UIKit 0x31588a93 _popViewControllerNormal + 191
11 UIKit 0x315888c1 -[UINavigationController _popViewControllerWithTransition:allowPoppingLast:] + 393
12 UIKit 0x31588e21 -[UINavigationController navigationBar:shouldPopItem:] + 153
13 UIKit 0x31588c37 -[UINavigationBar _popNavigationItemWithTransition:] + 99
14 UIKit 0x315d83ef -[UINavigationBar popNavigationItemAnimated:] + 123
15 UIKit 0x315d827d -[UINavigationBar _handleMouseUpAtPoint:] + 925
16 UIKit 0x315d7edb -[UINavigationBar touchesEnded:withEvent:] + 83
17 UIKit 0x31513ad3 -[UIWindow _sendTouchesForEvent:] + 319
18 UIKit 0x315134c1 -[UIWindow sendEvent:] + 381
19 UIKit 0x314f983d -[UIApplication sendEvent:] + 357
20 UIKit 0x314f90e3 _UIApplicationHandleEvent + 5827
21 GraphicsServices 0x3451c22b PurpleEventCallback + 883
22 CoreFoundation 0x34f2e523 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 39
23 CoreFoundation 0x34f2e4c5 __CFRunLoopDoSource1 + 141
24 CoreFoundation 0x34f2d313 __CFRunLoopRun + 1371
25 CoreFoundation 0x34eb04a5 CFRunLoopRunSpecific + 301
26 CoreFoundation 0x34eb036d CFRunLoopRunInMode + 105
27 GraphicsServices 0x3451b439 GSEventRunModal + 137
28 UIKit 0x31527e7d UIApplicationMain + 1081
29 MyApp 0x0000e699 main (main.m:9)
30 MyApp 0x00002868 start + 40