(见底部更新)
最近,当我的iPhone应用程序从后台返回时,我开始得到一个奇怪而罕见的崩溃.崩溃日志仅包含系统调用:
Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x00000138
Crashed Thread: 0
Thread 0 name: Dispatch queue: com.apple.main-thread
Thread 0 Crashed:
0 libobjc.A.dylib 0x34c715b0 objc_msgSend + 16
1 CoreFoundation 0x368b7034 _CFXNotificationPost + 1424
2 Foundation 0x34379d8c -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
3 UIKit 0x37ddfec2 -[UIApplication _handleApplicationResumeEvent:] + 1290
4 UIKit 0x37c37d5c -[UIApplication handleEvent:withNewEvent:] + 1288
5 UIKit 0x37c376d0 -[UIApplication sendEvent:] + 68
6 UIKit 0x37c3711e _UIApplicationHandleEvent + 6150
7 GraphicsServices 0x36dea5a0 _PurpleEventCallback + 588
8 CoreFoundation 0x3693b680 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + …Run Code Online (Sandbox Code Playgroud) 我有一个带自定义单元格的UITableView.当然,在cellForRowAtIndexPath中,我尝试将旧单元出列并重新使用它.每个单元格都有一个自动调整视图的层次结构:当我在cellForRowAtIndexPath中设置其内容时,我设置了顶视图的框架,并且其子视图相应地更改了它们的框架.请注意,行高也是动态的.当我只滚动表格(包含不同内容和帧的行)时,这一切都很好.但是我在该表的同一视图中也有一个文本字段,所以我需要滚动表的内容来补偿显示/隐藏的键盘.我为它设置了contentInset属性的动画:
// Called when the UIKeyboardWillHideNotification is sent
- (void)keyboardWillBeHidden:(NSNotification*)aNotification
{
NSTimeInterval animationDuration = [[aNotification.userInfo objectForKey:UIKeyboardAnimationDurationUserInfoKey] floatValue];
UIViewAnimationCurve animationCurve = [[aNotification.userInfo objectForKey:UIKeyboardAnimationCurveUserInfoKey] intValue];
[UIView setAnimationCurve:animationCurve];
[UIView animateWithDuration:animationDuration animations:^{
messagesTable.contentInset = UIEdgeInsetsMake(0, 0, kHSTableBottomInset, 0);
messagesTable.scrollIndicatorInsets = UIEdgeInsetsZero;
}];
}
Run Code Online (Sandbox Code Playgroud)
它也运行良好,但是有一个有趣的故障:当键盘被隐藏并且contentInset被动画恢复正常(kHSTableBottomInset是一个保持边距的小值)时,表重新加载将从上面滚动以显示的单元格.问题是这个重新加载也是在动画块中完成的!因此,当我在cellForRowAtIndexPath(被称为部件或重新加载)中更改出列的子视图帧(具体地,宽度)时,此更改也会被动画化,并且当单元格向下滚动以查看时,它也是可见的.我可以避免这种行为吗?