私はまだ目的の C を学んでおり、UITableViewControllerに少し奇妙な問題があります。これは CoreData によって取り込まれており、私はスタンフォード大学のCoreDataTableViewControllerクラスを使用しています。
アプリが最初に読み込まれると、表示されているすべての行にデータが表示されているため、テーブルはデータが取り込まれているように見えます。テーブルには Core Data の行数と一致する正しい行数がありますが、テーブル ビューをスクロールすると下のセルが空白になり、テーブル ビューの一番上までスクロールすると元のセルが表示されます。も空白です。最初にいくつかのデータを表示しているので、私は何が機能していません..
ありがとう
これはコードです:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [_fetchedResultsController.fetchedObjects count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *CellIdentifier = @"InfoCell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
UserAccount *account = [_fetchedResultsController objectAtIndexPath:indexPath];
UILabel *titleLabel = (UILabel *)[cell viewWithTag:1000];
UILabel *descriptionLabel = (UILabel *)[cell viewWithTag:1001];
titleLabel.text = account.title;
descriptionLabel.text = account.detail;
return cell;
}
私のviewWillAppearはこの関数を呼び出します:
- (void)setupFetchedResultsController
{
NSFetchRequest *request = [NSFetchRequest fetchRequestWithEntityName:@"UserAccount"];
request.sortDescriptors = [NSArray arrayWithObject:[NSSortDescriptor sortDescriptorWithKey:@"title"
ascending:YES
selector:@selector(localizedCaseInsensitiveCompare:)]];
_fetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:request
managedObjectContext:_managedObjectContext
sectionNameKeyPath:nil
cacheName:nil];
[self performFetch];
}