我已经搜索了与此相关的其他 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/