テーブルビューのためNSIndexPathを作成する方法
-
23-09-2019 - |
質問
私が定義した関数のテーブルの削除行1を必要とします。使用するためには、定義されたセクションと行とのdeleteRowAtIndexPath
を使用する必要がありますIndexPath
。どのように私はこのようなindexpathを作成することができますか?
クラッシュするその唯一のメンバーとしてINT {1}を持つ配列。セクションでは、必要があるとのNSLogメッセージの状態が良くとして定義されます。
*編集 - >コードが削除をセルに関連します:
NSIndexPath *myIP = [[NSIndexPath alloc] indexPathForRow:0 inSection:0];
NSArray *myArray = [[NSArray alloc] initWithObjects:myIP, nil];
// [self.tableView beginUpdates];
[self.tableView deleteRowsAtIndexPaths:myArray withRowAnimation:UITableViewRowAnimationFade];
// [self.tableView endUpdates];
解決
すばやくインデックスパスを作成するために使用し[NSIndexPath indexPathForRow:inSection:]
ます。
の編集の中スウィフト3:
let indexPath = IndexPath(row: rowIndex, section: sectionIndex)
他のヒント
indexPathForRow
クラスメソッドである!
のコードは次のようになります。
NSIndexPath *myIP = [NSIndexPath indexPathForRow:0 inSection:0] ;
スウィフトで必須の答え:NSIndexPath(forRow:row, inSection: section)
あなたはNSIndexPath.indexPathForRow(row, inSection: section)
が迅速に利用できず、あなたがindexPathを構築するために最初の方法を使用しなければならないことがわかります。
スウィフト3の場合、それは今だ:IndexPath(row: rowIndex, section: sectionIndex)
所属していません StackOverflow