ios - "Delete"滑动 UITableViewCell 时不显示

标签 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;
}

最佳答案

嗯,现在我觉得很傻。问题是 tableview 超出了父 View ,所以当我滑动时,我看不到 Delete 按钮。我修复了 tableview 的约束,现在它就像一个魅力一样工作。

关于ios - "Delete"滑动 UITableViewCell 时不显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29991947/

相关文章:

objective-c - 如何处理屏幕底部的滑动手势

objective-c - 如何在标签栏 Controller 上设置图像?

ios - 将 Base64 图像转换为 UIImage iOS

objective-c - 如何创建一个生成可移动图像的按钮? iOS 5

iphone - iOS UITableViewCell优化

ios - IOS 中的 GCM 通知未显示在状态栏上

ios - 为什么我的谷歌登录在我成功登录后不显示帐户选择?

ios - UIScrollView 和自动布局不起作用

ios - UITableView 重新加载不在顶部添加行

ios - 如何告诉 UITableView 自调整单元格的高度即将改变?