IB にプロトタイプのテーブルビューがあります。これには、完全なセルと基本セルの 2 種類のセルがあります (記事を表示するために、記事の種類に応じてそれぞれを使用します)。
FetchedResultsController をアプリに統合して、CoreData を使用してテーブルビューを設定できるようにしたいのですが、以前は (FetchedResultsController の代わりに NSArray を使用して) セルのセットアップを次のように処理しました。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
int row = indexPath.row;
static NSString *CellIdentifier = nil;
Article *article = self.articles[row];
// Checks if user simply added a body of text (not from a source or URL)
if (article.isUserAddedText) {
CellIdentifier = @"BasicArticleCell";
}
else {
CellIdentifier = @"FullArticleCell";
}
ArticleCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
// If the user simply added a body of text, only articlePreview and progress has to be set
cell.articlePreview.text = article.preview;
cell.articleProgress.text = [self calculateTimeLeft:article];
// If it's from a URL or a source, set title and URL
if (!article.isUserAddedText) {
cell.articleTitle.text = article.title;
cell.articleURL.text = article.URL;
}
return cell;
}
しかし、基本的な記事かどうかを確認する方法がわかりません (前に NSArray の Article オブジェクトのプロパティを確認したように)。私が見たある記事はこれをしました:
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
// Set up the cell...
[self configureCell:cell atIndexPath:indexPath];
return cell;
}
しかし、セル識別子が何であるかを決定する前に、それがどのような種類の記事であるかを知る必要があるため、ここでそれを行う方法がわかりません。FetchedResultController オブジェクトを早期に取得し、クエリを実行して article プロパティの値 (基本的かどうか) を確認し、それに応じて CellIdentifier を設定することはできますか? それとも他にやるべきことがありますか?
TL;DR: FetchedResultsController を使用するときに、セルに表示されるオブジェクトの種類に応じて CellIdentifier を決定するにはどうすればよいですか。