for(UIView *view in [_scrollView subviews]) {
NSMutableArray *_mutableArray = [_array mutableCopy];
[_mutableArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"guid like %@",view.object.guid]];
if([_mutableArray count] != 0) {
//object is already on screen we need to update it
[view setObject:(Object*)[_mutableArray objectAtIndex:0]];
}
else {
//object not on screen add it
_mutableArray = [_array mutableCopy];
[_mutableArray filterUsingPredicate:[NSPredicate predicateWithFormat:@"guid not like %@",view.object.guid]];
UIView *newView = [[UIView alloc] initWithObject:(Object*)[_mutableArray objectAtIndex:0]];
[_scrollView addSubview:newView];
}
}
如您所见,此方法会更新屏幕上的对象,如果对象不在屏幕上,则会创建该对象并将其添加到 scrollView 子视图层次结构中。现在我担心的是我在枚举它时修改了 scrollView 子视图层次结构。这最终会使我的应用程序崩溃吗?
如果是,如何修改上述代码以确保安全并实现相同的功能?
谢谢!