私は奇妙な問題に直面してUITableViewController
おり、sで作業していNSIndexPath
ます。私UITableView
は、クリックされたセルの下にフェードインし、その後フェードアウトするカスタム OptionCell を実装しました。iOS 4.3では問題なく動作します。
最近、新しい xCode と iOs 6 に更新しました。プロジェクト内の関連するポイントを変更したところ、customCell を削除しようとするたびに発生するクラッシュを除いて、すべてが機能します。
次のようにクラッシュします。
-[NSIndexPath 行] でのアサーションの失敗
[...]
*** キャッチされない例外 'NSInternalInconsistencyException' が原因でアプリを終了します。理由: 'UITableView で使用するインデックス パスが無効です。テーブル ビューに渡されるインデックス パスには、セクションと行を指定する正確に 2 つのインデックスが含まれている必要があります。可能であれば、UITableView.h の NSIndexPath 上のカテゴリを使用してください。
私はこのエラーについていくつかの調査を行いました。この質問を見つけ、上記の手順を確認しましたが、役に立ちませんでした。
デバッグ中に、のをチェックするたびにクラッシュすることがわかりましrow
たindexPathToDelete
。これは NIL ではなく、1 つある必要があります (古い iOS バージョンで動作します)。バージョン間で NSIndexPath に何か変更がありましたか? 考えられることはすべてチェックしました...
次のコード セグメントでエラーをマークしました。
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
if (indexPath.row == 0) {
/* if user tapped the same row twice get rid of the OptionCell */
if([indexPath isEqual:self.tappedIndexPath]){
[tableView deselectRowAtIndexPath:indexPath animated:YES];
}
/* update the indexpath if needed...*/
indexPath = [self modelIndexPathforIndexPath:indexPath];
/* pointer to delete the control cell */
NSIndexPath *indexPathToDelete = self.controlRowIndexPath;
/* if same row is tapped twice => clear tapping trackers */
if([indexPath isEqual:self.tappedIndexPath]){
self.tappedIndexPath = nil;
self.controlRowIndexPath = nil;
}
/* otherwise update them appropriately */
else{
self.tappedIndexPath = indexPath; /* the row the user just tapped. */
/* Now set the location of where I need to add the option cell */
self.controlRowIndexPath = [NSIndexPath indexPathForRow:indexPath.row + 1 inSection:indexPath.section];
}
/* all logic is done, lets start updating the table */
[tableView beginUpdates];
/* lets delete the control cell, either the user tapped the same row twice or tapped another row */
if(indexPathToDelete){
/* CRASH APPEARS HERE!: */
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPathToDelete]
withRowAnimation:UITableViewRowAnimationRight];
}
/* lets add the new control cell in the right place */
if(self.controlRowIndexPath){
[self.tableView insertRowsAtIndexPaths:[NSArray arrayWithObject:self.controlRowIndexPath]
withRowAnimation:UITableViewRowAnimationLeft];
// [self.tableView scrollToRowAtIndexPath:self.controlRowIndexPath atScrollPosition:UITableViewScrollPositionMiddle animated:YES];
}
/* and we are done... */
[tableView endUpdates];
} else {
if (self.controlRowIndexPath) {
indexPath = [self modelIndexPathforIndexPath:indexPath];
NSIndexPath *indexPathToDelete = self.controlRowIndexPath;
self.tappedIndexPath = nil;
self.controlRowIndexPath = nil;
if(indexPathToDelete){
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPathToDelete]
withRowAnimation:UITableViewRowAnimationFade];
}
}
VerwaltungViewController* verwaltungViewController;
verwaltungViewController = [[VerwaltungViewController alloc] init];
[self.navigationController pushViewController:verwaltungViewController animated:YES];
}
}
編集: indexPathのmodelIndexPath:
- (NSIndexPath *)modelIndexPathforIndexPath:(NSIndexPath *)indexPath
{
int whereIsTheControlRow = self.controlRowIndexPath.row;
if(self.controlRowIndexPath != nil && indexPath.row > whereIsTheControlRow)
return [NSIndexPath indexPathForRow:indexPath.row - 1 inSection:0];
return indexPath;
}