Iphone UIActionSheet用于在“取消”时删除UITableView单元格的操作表将持续显示按下的“删除”按钮
在表视图中删除一行时,我希望在某些情况下显示一个请求确认的操作表。当操作表回答“是”(破坏性操作)时,我删除表行,一切正常。但当按下“取消”时,我仍然看到“删除”按钮处于按下状态 删除时,我在Iphone UIActionSheet用于在“取消”时删除UITableView单元格的操作表将持续显示按下的“删除”按钮,iphone,ios,uitableview,Iphone,Ios,Uitableview,在表视图中删除一行时,我希望在某些情况下显示一个请求确认的操作表。当操作表回答“是”(破坏性操作)时,我删除表行,一切正常。但当按下“取消”时,我仍然看到“删除”按钮处于按下状态 删除时,我在tableView:committeeditingstyle中所做的是: BlockBasedActionSheet *askSheet = [[BlockBasedActionSheet alloc] initWithTitle:@"Delete entry?"
tableView:committeeditingstyle
中所做的是:
BlockBasedActionSheet *askSheet =
[[BlockBasedActionSheet alloc]
initWithTitle:@"Delete entry?"
cancelButtonTitle:@"No"
destructiveButtonTitle:@"Yes, delete child also records"
cancelAction:^{
UITableViewCell *cell = [self tableView:tableView cellForRowAtIndexPath:indexPath];
if (cell.showingDeleteConfirmation) {
cell.editing = NO;
cell.editingAccessoryView = nil;
cell.editing = YES;
}
}
destructiveAction:deleteBlock];
[askSheet showInView:self.view];
[askSheet release];
同样奇怪的是,单元格的属性showingDeleteConfirmation
是NO
,尽管删除按钮仍然可见
我正在使用自制的基于块的操作表实现。虽然我似乎在cancel块中获得了正确的单元格,但可能存在错误
那么,我如何将删除按钮的状态重置为“未按下”并将其移除,然后将圆形删除按钮转回水平位置,就像我在屏幕上点击某个位置时发生的那样
Helper类BlockBasedActionSheet.h
:
@interface BlockBasedActionSheet : UIActionSheet<UIActionSheetDelegate> {
}
@property (copy) void (^cancelBlock)();
@property (copy) void (^destructiveBlock)();
- (id)initWithTitle:(NSString *)title cancelButtonTitle:(NSString *)cancelButtonTitle destructiveButtonTitle:(NSString *)destructiveButtonTitle cancelAction:(void (^)())cancelBlock destructiveAction:(void (^)())destructiveBlock;
@end
在:中,不应在此方法的实现中调用setEditing:animated:。如果出于某种原因,必须在延迟后使用performSelector:withObject:afterDelay:方法调用它
我的理解是,一旦删除按钮开始消失,就会调用此方法(因此,showingDeleteConfirmation
是NO
),因此不会调用块中if语句中的内容。如果你在那里设置了一个断点,对吗
在任何情况下,您都可能希望按照文档中的说明操作,并在毫秒延迟后让表返回编辑模式
编辑/更新
在Xcode中创建了一个新的基于导航的项目。更改了此代码。将表设置为显示10行,每行以文本形式显示其索引XPath。如果你想要整件事。你需要刷卡才能删除,我没有专门的删除按钮
在cell对象上调用setEditing
没有任何作用,即使使用了performSelector…
(我不知道为什么)。但您可以在表视图上调用setEditing
,据我所知,它会执行您希望它执行的操作(将其返回到水平删除图标,不带删除按钮)
如果这不能解决您的问题,那么我真的不确定还能做些什么:/
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
BlockBasedActionSheet *askSheet =
[[BlockBasedActionSheet alloc]
initWithTitle:@"Delete entry?"
cancelButtonTitle:@"No"
destructiveButtonTitle:@"Yes, delete child also records"
cancelAction:^{
[self.tableView setEditing:YES animated:YES];
}
destructiveAction:^{
NSLog(@"Delete block called");
}];
[askSheet showInView:self.view];
[askSheet release];
}
因此,它的工作原理是将第一个代码段替换为
BlockBasedActionSheet *askSheet =
[[BlockBasedActionSheet alloc]
initWithTitle:@"Delete entry?"
cancelButtonTitle:@"No"
destructiveButtonTitle:@"Yes, delete also child records"
cancelAction:^{
// this resets the delete button
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
destructiveAction:deleteBlock];
[askSheet showInView:self.view];
[askSheet release];
重新加载行就可以了。是的,这就是我想说的,在我选中showingDeleteConfirmation的行中,它已经是否了。因此,如果
-block,我还可以删除这个。但我仍然希望删除按钮消失。我不知道当我确认的时候到底发生了什么,因为那时这一行就消失了。也许这就是API所期望的,因此不再关心按钮及其状态(仍显示为按下状态)是的,因此如果希望删除按钮消失,请设置一个间隔为几毫秒的计时器。0.1秒后(使用performSelector:withObject:afterDelay
)显示删除确认
仍然是否
。即使在没有if
(切换编辑并将视图设置为nil
)的情况下执行块也绝对没有效果。顺便说一句,文档中提到的是UITableView
。我在UITableViewCell
上切换编辑模式。更新了我的答案。我找不到切换单个UITableViewCell
的编辑模式的方法。
BlockBasedActionSheet *askSheet =
[[BlockBasedActionSheet alloc]
initWithTitle:@"Delete entry?"
cancelButtonTitle:@"No"
destructiveButtonTitle:@"Yes, delete also child records"
cancelAction:^{
// this resets the delete button
[tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath]
withRowAnimation:UITableViewRowAnimationFade];
}
destructiveAction:deleteBlock];
[askSheet showInView:self.view];
[askSheet release];