【发布时间】:2014-07-21 11:28:01
【问题描述】:
我在 UITableView 中使用从 XIB 加载的单元格的滑动删除功能遇到问题。正如您在下面看到的,当我将单元格向左滑动时,图像会向左移动,但标签不会。所以标签覆盖了删除按钮。您可以在下面找到我已实现的代码:
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
if (editingStyle == UITableViewCellEditingStyleDelete) {
//remove the deleted object from your data source.
//If your data source is an NSMutableArray, do this
}
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"MostKadroCell";
MostKadroCell *cell = (MostKadroCell *)[tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
[cell setSelectionStyle:UITableViewCellSelectionStyleNone];
[cell.contentView setUserInteractionEnabled: NO]; //
cell.lblKadroName.text = [arrKadroName objectAtIndex:indexPath.row];
[cell.imageView setImage:[UIImage imageNamed:strImage]];
return cell;
}
- (void)viewDidLoad
{
[super viewDidLoad];
UINib *nib = [UINib nibWithNibName:@"MostKadroCell" bundle:nil];
[self.tableMostKadro registerNib:nib forCellReuseIdentifier:@"MostKadroCell"];
....
【问题讨论】:
-
您可能需要将标签“粘贴”到单元格的左边缘或Interface Builder中的
UIImageView。 -
使用
NSLayoutConstraint设置自定义单元格的布局。可以在 IB 中添加,也可以在代码中添加。 -
虽然我粘贴并使用了布局中的约束,但它不起作用。
标签: ios uitableview