ビューを非同期で読み込もうとしています。問題は、読み込まれるビューのフレームが、非同期で読み込まれるデータに依存することです。つまり、UIView を実際に表示する場所を決定する長い計算がいくつかあります。
スレッドで UIView を実際に表示しようとすると問題が発生し、常にメイン スレッドにロードする必要があることを知っているので、これは私が試したコードです。
asyncQueue = [[NSOperationQueue alloc] init];
[asyncQueue addOperationWithBlock:^{
// Do work to load the UIViews and figure out where they should be
UIButton *test = [[UIButton alloc] initWithFrame:[self doWorkToGetFrame]];
[[NSOperationQueue mainQueue] addOperationWithBlock:^{
[self addSubview:test];
}
}];
}];
これはすべて UIView コンテナにあります。