私にはtableviewController
があります。 UINavigationBar
には、「編集」というボタンが追加されます。ユーザーがそれをクリックすると、すべてのセルを編集モードにする必要があります。そこではレコードを削除できます。テーブルからセルを削除する - コードが提供されました
次のような方法があります。私は正しいですか?編集ボタンをクリックすると、赤い円とセルの削除ボタンが表示されますか?
2.)編集ボタン(UIBarbuttonitem
)のコードをユーザーがクリックすると、次のメソッドを呼び出す方法を教えてください。
3.)セルを削除すると、テーブルのデータをリロードする必要があります。私はこれのためのコードを書いた、それは正しいですか? (私は現時点でMacにはない)
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
// Delete the row from the data source
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
[self.tableView beginUpdates];
[discardedItems addObject:[self.entries objectAtIndex:indexPath.row]];
[self.itemsMutableArray removeObjectsInArray:discardedItems ];
self.entries = [NSArray arrayWithArray:self.itemsMutableArray];
[self.tableView endUpdates];
[self.tableView reloadData];
}
else if (editingStyle == UITableViewCellEditingStyleInsert) {
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
}
}
itemsMutableArrayは何のために使用しますか?あなたは変更可能な配列としてエントリを持つことはできませんか? – SEG
'entries'配列の内容をコピーしましたので、簡単に項目を削除してから' entries'配列に再割り当てすることができました。 – shajem