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 サブビュー階層に追加されます。今私の懸念は、スクロールビューのサブビュー階層を列挙しながら変更していることです。これにより、最終的にアプリがクラッシュしますか?
はいの場合、上記のコードを安全に変更して同じ機能を実現するにはどうすればよいですか?
ありがとう!