我们在同一个名为" MyViewController"
的ViewController中即使它崩溃也难以重现,但我们从崩溃中得到了这次崩溃......
- (void)dismiss {
MyViewController* __weak weakSelf = self;---->//Crashing here
[UIView animateWithDuration:0.25 animations:^{
MyViewController* __strong strongSelf = weakSelf;
if (strongSelf) {
CGRect backFrame = strongSelf.shroud.frame;
strongSelf.shroud.backgroundImageView.frame = backFrame;
strongSelf.shroud.shadedOverlay.backgroundColor = [UIColor colorWithWhite:0 alpha:0];
CGRect semiViewFrame = CGRectMake(0, strongSelf.view.frame.size.height, strongSelf.shroud.contentView.frame.size.width, strongSelf.shroud.contentView.frame.size.height);
strongSelf.shroud.contentView.frame = semiViewFrame;
}
}
completion:^(BOOL finished){
MyViewController* __strong strongSelf = weakSelf;
if (strongSelf) {
[strongSelf.shroud removeFromSuperview];
strongSelf.shroud = nil;
strongSelf.semiViewController = nil;
}
}];}
我们从崩溃分析中获得以下崩溃日志:
Thread : Crashed: com.apple.main-thread
0 libobjc.A.dylib 0x39d148f8 _objc_trap() + 18446744073709552000
1 libobjc.A.dylib 0x39d1495d _objc_inform
2 libobjc.A.dylib 0x39d233cb weak_register_no_lock + 182
3 libobjc.A.dylib 0x39d236ff objc_storeWeak + 110
4 applicationName 0x000e8071 -[MyViewController dismiss] (MyViewController:144)
5 UIKit 0x31f357f9 _UIGestureRecognizerSendActions + 196
6 UIKit 0x31de0a93 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 1138
7 UIKit 0x321880bf ___UIGestureRecognizerUpdate_block_invoke + 46
8 UIKit 0x31da794f _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 218
9 UIKit 0x31da60b3 _UIGestureRecognizerUpdate + 298
10 UIKit 0x31ddf305 -[UIWindow _sendGesturesForEvent:] + 772
11 UIKit 0x31ddec2b -[UIWindow sendEvent:] + 666
12 UIKit 0x31db3e55 -[UIApplication sendEvent:] + 196
13 UIKit 0x31db2521 _UIApplicationHandleEventQueue + 7120
14 CoreFoundation 0x2f548faf __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 14
15 CoreFoundation 0x2f548477 __CFRunLoopDoSources0 + 206
16 CoreFoundation 0x2f546c67 __CFRunLoopRun + 630
17 CoreFoundation 0x2f4b1729 CFRunLoopRunSpecific + 524
18 CoreFoundation 0x2f4b150b CFRunLoopRunInMode + 106
19 GraphicsServices 0x344106d3 GSEventRunModal + 138
20 UIKit 0x31e12871 UIApplicationMain + 1136
请帮我解决这个问题......
提前致谢
答案 0 :(得分:1)
你不需要在这里做强/弱舞,因为没有保留周期。该块具有对该视图的强引用,但该视图没有对该块的强引用。当动画结束时,块会释放视图。
答案 1 :(得分:0)
Nanda请改变你的代码
MyViewController* __strong weakSelf = self;
通过使这个弱点你正在尝试访问不在内存中的weakSelf,你正在崩溃。