Posted at --.--.-- Category : スポンサー広告
Posted at 2009.11.12 Category : Table View
こまごましたところは省略で。
問題となったのは、セルを削除しても動的にリストが更新されない点。
つまり、完了ボタンの押下時にまとめて更新される。
一応解決できたのでメモ。
問題となったのは、セルを削除しても動的にリストが更新されない点。
つまり、完了ボタンの押下時にまとめて更新される。
一応解決できたのでメモ。
以下、解決前のコード
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// Handle deletion requests
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[dataList removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}
// Enter edit mode by changing "Edit" to "Done"
-(void)enterEditMode {
// Add the edit button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"完了"
style:UIBarButtonItemStylePlain
target:self
action:@selector(leaveEditMode)]
autorelease];
[self.tableView setEditing:YES animated:YES];
[self.tableView beginUpdates];
}
// Finished with edit mode, so restore the buttons and commit changes
-(void)leaveEditMode {
// Add the edit button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"編集"
style:UIBarButtonItemStylePlain
target:self
action:@selector(enterEditMode)]
autorelease];
[self.tableView endUpdates];
[self.tableView setEditing:NO animated:YES];
}
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
そんでもって、以下が解決後のコード
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// Handle deletion requests
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView beginUpdates];
if (editingStyle == UITableViewCellEditingStyleDelete) {
[dataList removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
[self.tableView endUpdates];
}
// Enter edit mode by changing "Edit" to "Done"
-(void)enterEditMode {
// Add the edit button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"完了"
style:UIBarButtonItemStylePlain
target:self
action:@selector(leaveEditMode)]
autorelease];
[self.tableView setEditing:YES animated:YES];
}
// Finished with edit mode, so restore the buttons and commit changes
-(void)leaveEditMode {
// Add the edit button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"編集"
style:UIBarButtonItemStylePlain
target:self
action:@selector(enterEditMode)]
autorelease];
[self.tableView setEditing:NO animated:YES];
}
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
違いは何かと言うと
[self.tableView beginUpdates];
[self.tableView endUpdates];
の位置。
解決前は、編集ボタンと完了ボタンそれをれを押下した時点で呼び出していた。
だから、削除の処理を完了して、ボタンを押下するまで表示が更新されなかった。
解決後は、「削除の命令が飛んで来て、配列からデータを削除」という処理の
前後にそれぞれを記述している。
つまり、削除命令を受け取って、削除処理を完了する度に時点で表示の更新をしている。
…表現が難しい。
解決前は、全ての作業を完了してから更新している。
解決後は、1件の作業を完了する度に更新している。
と、言えばわかりやすくはなるのか?
とにかく、ひとまず解決。
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// Handle deletion requests
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
[dataList removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
}
// Enter edit mode by changing "Edit" to "Done"
-(void)enterEditMode {
// Add the edit button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"完了"
style:UIBarButtonItemStylePlain
target:self
action:@selector(leaveEditMode)]
autorelease];
[self.tableView setEditing:YES animated:YES];
[self.tableView beginUpdates];
}
// Finished with edit mode, so restore the buttons and commit changes
-(void)leaveEditMode {
// Add the edit button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"編集"
style:UIBarButtonItemStylePlain
target:self
action:@selector(enterEditMode)]
autorelease];
[self.tableView endUpdates];
[self.tableView setEditing:NO animated:YES];
}
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
そんでもって、以下が解決後のコード
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
// Handle deletion requests
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
[self.tableView beginUpdates];
if (editingStyle == UITableViewCellEditingStyleDelete) {
[dataList removeObjectAtIndex:indexPath.row];
[self.tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
[self.tableView endUpdates];
}
// Enter edit mode by changing "Edit" to "Done"
-(void)enterEditMode {
// Add the edit button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"完了"
style:UIBarButtonItemStylePlain
target:self
action:@selector(leaveEditMode)]
autorelease];
[self.tableView setEditing:YES animated:YES];
}
// Finished with edit mode, so restore the buttons and commit changes
-(void)leaveEditMode {
// Add the edit button
self.navigationItem.rightBarButtonItem = [[[UIBarButtonItem alloc]
initWithTitle:@"編集"
style:UIBarButtonItemStylePlain
target:self
action:@selector(enterEditMode)]
autorelease];
[self.tableView setEditing:NO animated:YES];
}
/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/
違いは何かと言うと
[self.tableView beginUpdates];
[self.tableView endUpdates];
の位置。
解決前は、編集ボタンと完了ボタンそれをれを押下した時点で呼び出していた。
だから、削除の処理を完了して、ボタンを押下するまで表示が更新されなかった。
解決後は、「削除の命令が飛んで来て、配列からデータを削除」という処理の
前後にそれぞれを記述している。
つまり、削除命令を受け取って、削除処理を完了する度に時点で表示の更新をしている。
…表現が難しい。
解決前は、全ての作業を完了してから更新している。
解決後は、1件の作業を完了する度に更新している。
と、言えばわかりやすくはなるのか?
とにかく、ひとまず解決。

Tracback
この記事にトラックバックする(FC2ブログユーザー)