(1) 需要一個button/選項, 在執行後做以下動作, 可開啟刪除的畫面
[self.tableView setEditing:YES animated:YES];
(2-1) 並於程 中加入以下方法, 此為多選
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}
{
return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}
(2-2) 並於程 中加入以下方法, 此為單選
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
} 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.
}
}
++++++++++++++++++範例下載++++++++++++++++++
[多刪]這個網址, 大推!
http://rainbird.blog.51cto.com/211214/636270
[單刪]在Xcode中即可建立
(a) 開啟Mac中的Xcode
(b) File > New > Project
(c) [iOS]Application > Master-Detail Application
(d) Next
{
if (editingStyle == UITableViewCellEditingStyleDelete) {
[_objects removeObjectAtIndex:indexPath.row];
[tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
} 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.
}
}
++++++++++++++++++範例下載++++++++++++++++++
[多刪]這個網址, 大推!
http://rainbird.blog.51cto.com/211214/636270
[單刪]在Xcode中即可建立
(a) 開啟Mac中的Xcode
(b) File > New > Project
(c) [iOS]Application > Master-Detail Application
(d) Next
沒有留言:
張貼留言