下面的屏幕截图显示了在行上向左滑动后处于编辑模式的一个表格 View 单元格。在编辑模式下,我可以按住单元格并再次向左拖动,这会显示这个空白区域(当我放手时有弹性效果)。我将每个单元格的背景图片设置如下:
cell.backgroundView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"CellBG.jpg"]];
我有 2 个问题。
- 是否有可能阻止这种额外的拖动,从而永远不会看到这个白色区域?例如,想要与 iOS7 天气应用程序相同的行为。
- 另外,知道为什么删除按钮下方有细白线吗?
谢谢
最佳答案
- Is it possible to prevent this extra dragging so this white area will never be seen?
是的。将图像放在 UITableView
的背景上。不在手机上。因为如果你把图像背景放在一个单元格上,当你水平交换一个要删除的单元格时,那个单元格会移动。也就是说图像背景也会移动。但是如果你把它放在 UITableView
上,它就不会随 swap 移动。请记住将 UITableView
和 UITableViewCell
的背景颜色设置为清晰的颜色。
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"ReuseIdentifier"];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"cellBackground.png"]];
imageView.frame = CGRectMake(0, kCellHeight*indexPath.row, 320, cell.frame.size.height);
[tableView addSubview:imageView];
[tableView sendSubviewToBack:imageView];
return cell;
}
2.Also, any idea why there is thin white line under the delete button?
我认为这是 Apple 的小错误。您也可以在天气应用程序中找到它。所以别管那个。
关于ios - 防止在 iOS7 tableview 编辑模式下向左拖动单元格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18950629/