ビューコントローラ(タブ1)で、次のようにコアデータからロードします。
- (void)loadRecordsFromCoreData {
[self.managedObjectContext performBlockAndWait:^{
NSError *error = nil;
NSFetchRequest *request = [[NSFetchRequest alloc] initWithEntityName:@"Item"];
[request setSortDescriptors:[NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"order" ascending:YES]]];
self.items = [self.managedObjectContext executeFetchRequest:request error:&error];
}];
}
次に、次のようなアイテムを表示します(viewDidAppearに):
- (void)displayItems
{
for(UIView *subview in [self.itemRow subviews]) {
[subview removeFromSuperview];
}
int xPos = kXItemOffsetIphone;
for (Item *item in self.items) {
ItemView *itemView = [[ItemView alloc] initWithFrame:CGRectMake(xPos, kYItemOffsetIphone, kItemWidthIphone, kItemHeightIphone) ];
[itemView layoutWithData:item];
[self.itemRow addSubview:itemView];
xPos += kXItemSpacingIphone;
}
}
ItemViewは、アイテムなどに関連付けられた画像を表示するUIViewサブクラスです。アプリを最初に実行すると、すべてのアイテムが表示されます。ただし、別のタブをクリックしてからタブ1に戻ると、すべてのアイテムが表示されなくなります。アイテム配列はまだ存在しますが、配列内の各アイテムは「障害」であるため、何も表示されません。とてもイライラします。これらのアイテムが「障害」になるのを防ぐにはどうすればよいですか?