"删除"在刷UITableViewCell时没有显示

时间:2015-05-01 17:34:22

标签: ios objective-c uitableview

我已经搜索了与此相关的其他SO链接,其他解决方案似乎都没有用!如果有人有洞察力,我会喜欢!以下是相关代码。我滑动时发生的是单元格向左移动,但删除按钮所在的空格是空的。

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSLog (@"%i",indexPath.row);
    return UITableViewCellEditingStyleDelete;
}

- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
    //Do other delete stuff
}


-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath{
    return YES;
}

我认为也许tableView:editingStyleForIndexPath没有被调用,但我的NSLog显示它是。

我已尝试设置[self.tableView isEditing = YES],但仍然会导致空滑动。

以下是设置tableview的代码:

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {

return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [receiptsArray count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @"Cell";

    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
            cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier];
    }

    cell.textLabel.text = [receiptsArray objectAtIndex:indexPath.row];

    cell.imageView.image = [UIImage imageWithContentsOfFile:[NSString stringWithFormat:@"%@/%@/%@",[self getPathToDocumentsDirectory],self.nameOfRetailer,[receiptsArray objectAtIndex:indexPath.row]]];

return cell;
}

1 个答案:

答案 0 :(得分:-1)

嗯,现在我觉得很傻。问题是tableview扩展到父视图之外,所以当我滑动时,我看不到Delete按钮。我修复了tableview的约束,现在它就像一个魅力。

相关问题