UITableView,拦截编辑模式 [英] UITableView, intercepting Edit mode
问题描述
我很好奇,如果可以拦截UITableView上的编辑模式的默认方法。通常,如果你向旁边滑动具有与其相关联的委托方法的UITableViewCell,则会获得一个免费的删除按钮。我想更改删除到一些其他,任意选择器。而不是删除单元格,我只想运行一个hello世界警报对话框。在某种程度上是可能的吗?
编辑是在UITableView的委托对象上实现为一个方法。在你的表控制器中,有任何控制激活编辑调用这个:
[tableView setEditing:YES animated:YES];然后,确保你的委托对象实现这个:
$ b
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if(editingStyle == UITableViewCellEditingStyleDelete) {
UIAlertView * alert = [[UIAlertView alloc]
initWithTitle:@Delete
message:@你真的要删除George W. Bush吗?
delegate:self
cancelButtonTitle:@Cancel
otherButtonTitles:@当然!,nil];
}
}
...或更标准的操作可能是: p>
[itemList removeObjectAtIndex:indexPath.row];
[table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
I'm curious if it's possible to intercept the default methods of 'Edit' mode on a UITableView. Typically you get a free 'delete' button if you side swipe a UITableViewCell that has delegate methods associated with it. I'd like to change the delete to some other, arbitrary selector. Instead of deleting the cell, I'd just like to run a hello world alert dialogue. Is something to this extent possible?
解决方案 Editing is implemented as a method on your UITableView’s delegate object. In your table controller, have whatever control activates editing call this:
[tableView setEditing: YES animated: YES];
Then, make sure that your delegate object implements this:
- (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];
}
}
…or a more standard action might be:
[itemList removeObjectAtIndex:indexPath.row];
[table deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:YES];
这篇关于UITableView,拦截编辑模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!