問題のアプリにはユーザーがアイテムをお気に入りとしてマークする機能があります。ユーザーにお気に入りが保存されていないときは、その旨を通知したいと思います(空白のtableViewのアイデアはほとんどありません)。tableViewのデータがないときにカスタムラベルを表示
私のnumberOfRowsInSection
は、ユーザーがお気に入りとしてマークしたアイテムがない場合はゼロです。私はcell.textLabel.text = @ "あなたはお気に入りがありません"と設定したいのですが、テーブルの項目がないときはcellForRowAtIndexPath
が呼び出されません。
0に遭遇した後、cellForRowAtIndexPath
で1行をテストしてから、カスタムテキストを挿入すると、結果が出るかもしれませんが、お気に入りが1つしかない場合はどうなりますか?私は上記の持っていた、と下のお勧めしますが、おそらく私はおそらく、それはときに、テーブルを更新するために、デリゲートメソッドでfetchedResultsControllerだという事実のために、右のそれをやっていないよなアイデアを実装しようとした
UPDATE
変更が発生します。
*** Assertion failure in -[UITableView _endCellAnimationsWithContext:], /SourceCache/UIKit_Sim/UIKit-1447.6.4/UITableView.m:976 Serious application error. An exception was caught from the delegate of NSFetchedResultsController during a call to -controllerDidChangeContent:. Invalid update: invalid number of rows in section 0. The number of rows contained in an existing section after the update (1) must be equal to the number of rows contained in that section before the update (1), plus or minus the number of rows inserted or deleted from that section (0 inserted, 1 deleted). with userInfo (null)
、それはでクラッシュ最初の場所に表示すべきセルが存在しない:
私はしかし、1個のテーブル内のセルがある場合、私は、セルを削除すると、このエラーが出ますここで
*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[_PFBatchFaultingArray objectAtIndex:]: index (0) beyond bounds (0)'
関連するコードです:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
// Return the number of rows in the section.
id <NSFetchedResultsSectionInfo> sectionInfo = [[_fetchedResultsController sections] objectAtIndex:section];
if ([sectionInfo numberOfObjects]==0) {
return 1;
} else {
return [sectionInfo numberOfObjects];
}
}
- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath {
if ([[_fetchedResultsController sections] objectAtIndex:0]==0) {
cell.textLabel.text = @"You have no favorites";
} else {
Shows *show = [_fetchedResultsController objectAtIndexPath:indexPath];
cell.textLabel.text = show.ShowsToSerials.serialName;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%@", show.showTitle];
}
}
ソリューション1のコードを投稿してもよろしいですか? –
ダニエル。コードにもう一度感謝します。メモリ管理に関する単なる質問です。私はdeallocでそのビューを解放します(それは最善でしょうか?)しかし、どこでラベルをリリースすべきですか? –
私はビューを持っており、すべてがdeallocでリリースされています。私は何かが私のために漏れているとは思わない。 –