在“ContainerViewControler”的#viewDidAppear上,发布 UIAccessibilityScreenChangedNotification 会导致间歇性崩溃,异常类型为:EXC_CRASH (SIGABRT)。
-(void)viewDidAppear:(BOOL)animated
{
UIAccessibilityPostNotification(UIAccessibilityScreenChangedNotification, self.childController.collectionView);
}
附上了带有堆栈跟踪的屏幕截图。
在尝试调试时,在帧 'objc_exception_throw' 上,确实在 $r0 处得到了异常
(lldb) po $r0 *** -[__NSArrayM objectAtIndex:]:空数组的索引 0 超出范围
在帧 '_UIAXBroadcastMainThread' 上,在 $r8 处获得集合视图中的一个单元格
(lldb) po $r8
<UICollectionViewCell: 0x15711ae0; baseClass = UICollectionViewCell; frame = (0 0; 320 278); opaque = NO; gestureRecognizers = <NSArray: 0x15709f90>; layer = <CALayer: 0x157119b0>>
印象中在childController上的collectionView出现和可访问性通知传递之间存在时间问题,但无法为其编写测试。
要求更好地了解 UIAccessibility 期望 NSArray 持有什么以及导致索引超出范围的原因。
这是在
iOS 7
iPhone 4、iPhone 5上
编辑
由于崩溃是间歇性的,因此调动了#objectAtIndex: 方法以查看预期数组包含的内容。
@implementation NSMutableArray (Debug)
- (id)myObjectAtIndex:(NSUInteger)index
{
return [self myObjectAtIndex:index];
}
+ (void)load {
NSLog(@"Swizzling method ...");
Class arrayClass = NSClassFromString(@"__NSArrayM");
Method originalMethod = class_getInstanceMethod(arrayClass, @selector(objectAtIndex:));
Method categoryMethod = class_getInstanceMethod(arrayClass, @selector(myObjectAtIndex:));
method_exchangeImplementations(originalMethod, categoryMethod);
}
@end
看起来该数组包含所有 UIView 实例,这些实例是集合视图的 UICollectionViewCell 的子视图,通知已发布并启用了“可访问性”。
不确定 UIAccessibility 如何填充该数组。
想知道它是否假定大小等于启用了“可访问性”的每个 UIView 但无法根据某些条件填充数组.