Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/99.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIActionSheet用于在“取消”时删除UITableView单元格的操作表将持续显示按下的“删除”按钮_Iphone_Ios_Uitableview - Fatal编程技术网

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];