iOS UITableView滑动左按钮不会出现

时间:2014-12-24 09:51:37

标签: ios objective-c uitableview

我正在尝试向左滑动以显示删除按钮。 单元格向左移动,但没有可见的按钮。为什么会这样?解决方案是什么?

要说清楚,我已经在StackOverflow上搜索并尝试了至少十几个发布的“解决方案”,但其中没有一个对我有效。

提前致谢。

我尝试使用以下代码,这似乎使表格单元格移动,但日志不会显示NSLog(@"commitEditingStyle");。为什么会这样?

// Swipe to delete.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog(@"commitEditingStyle");
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        NSLog(@"UITableViewCellEditingStyleDelete");
        [listData removeObjectAtIndex:indexPath.row];
        [self.tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
        [self.tableView reloadData];
    }
}

我尝试添加:

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{

    return YES;
}

以下是截图:

No delete button

2 个答案:

答案 0 :(得分:0)

问题是表格大小比我的屏幕尺寸大。解决方案是设置约束以匹配视图的宽度。

答案 1 :(得分:0)

// During startup (-viewDidLoad or in storyboard) do:
self.tableView.allowsMultipleSelectionDuringEditing = NO;

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

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        //add code here for when you hit delete
    }    
}
相关问题