Coo*_*coa 13 iphone cocoa-touch
我很好奇是否有可能拦截UITableView上"编辑"模式的默认方法.通常,如果您侧面滑动具有与之关联的委托方法的UITableViewCell,则会获得一个免费的"删除"按钮.我想将删除更改为其他任意选择器.我不想删除单元格,而是想运行一个hello world alert对话框.这种程度有可能吗?
小智 21
编辑作为UITableView的委托对象上的方法实现.在你的表控制器中,有任何控件激活编辑调用:
[tableView setEditing: YES animated: YES];
Run Code Online (Sandbox Code Playgroud)
然后,确保您的委托对象实现了这个:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
UIAlertView *alert = [[UIAlertView alloc]
initWithTitle: @"Delete"
message: @"Do you really want to delete “George W. Bush”?"
delegate: self
cancelButtonTitle: @"Cancel"
otherButtonTitles: @"Of course!", nil];
}
}
Run Code Online (Sandbox Code Playgroud)
......或者更标准的行动可能是:
[itemList removeObjectAtIndex:indexPath.row];
[table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
Run Code Online (Sandbox Code Playgroud)
@JFMartin和Marco - 要替换标准的"删除"按钮,请使用以下UITableview委托方法
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
Run Code Online (Sandbox Code Playgroud)
UITableViewCell 上有一个名为 的属性editAction,记录为允许您更改用于在单个单元格上插入或删除的操作(它target也使用单元格的属性)。我还没有测试过,但这听起来可能会达到你想要的效果。
| 归档时间: |
|
| 查看次数: |
22995 次 |
| 最近记录: |