0

I have a button that triggers [sppvc setEditing:!sppvc.isEditing animated:YES]; and the delete symbols come up but nothing happens when you click them(they dont rotate nor does the delete button show like it does when you slide to delete), also they dont slide things over when they appear. I should mention sliding to delete works fine.

Heres a picture to explain what I mean:

enter image description here

UPDATE: holding the red delete symbol / sign and letting go after a couple of seconds causes the delete button to come up. how can I make this instant.

4

4 回答 4

1

您需要实现以下代码。它是 UItableview 的委托方法,每当您滑动单元格以进行删除时,它都会自动调用

    - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    // Return YES if you want the specified item to be editable.
    return YES;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //add code here for when you hit delete

}
}
于 2013-06-11T13:49:54.687 回答
0

Turns out

UITapGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideKeyboard)];
    [self.tableView addGestureRecognizer:gestureRecognizer];

creates this 3 second delay for the delete symbol to be activated. Hope this helps someone out.

This question helps fix that problem

UIButton inside a view that has a UITapGestureRecognizer

于 2013-06-11T14:38:50.627 回答
0

请使用此代码并告诉我它是否有效。

-(void)editButtonPressed:(id)sender
{
    if(self.editing)
    {
        [super setEditing:NO animated:YES]; 
        [selectSongTableView setEditing:NO animated:YES];
        [self.navigationItem.leftBarButtonItem setTitle:@"Edit"];
        [self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStylePlain];

    }
    else
    {

        [super setEditing:YES animated:YES]; 
        [selectSongTableView setEditing:YES animated:YES];
        [self.navigationItem.leftBarButtonItem setTitle:@"Done"];
        [self.navigationItem.leftBarButtonItem setStyle:UIBarButtonItemStyleDone];

    }  

}

如果您UITableView在点击任何按钮时执行编辑,请使用此代码。使用您自己的表名。

希望这会有所帮助,否则我在这里。

于 2013-06-11T14:32:53.477 回答
0

这种行为不能通过代码访问——它应该是自动的。这是您使用的设备还是模拟器?您所描述的听起来像是设备/模拟器处理触地事件的方式有问题,即您的应用程序之外的东西。如果您还没有这样做,我会尝试在另一台设备上运行该应用程序。

另一种可能性是,根据您提供的图像,删除按钮似乎覆盖了 tableviewcell 上的图像。每当删除符号出现时,您的整个单元格都应该缩进,包括其中的任何图像。这意味着图像以某种方式被识别为在您的 tableviewcell 之外,因此可能会干扰触摸事件。因此,您如何创建 tableviewcells(我假设它们是自定义的)和其中的 imageviews 可能是一个问题。最后,我过去忽略了自己的一件简单的事情。确保在您的单元格 nib 文件中选中了启用用户交互框。

于 2013-06-11T14:35:37.660 回答