【问题标题】:Custom UITableViewCell is not showing indent while editing自定义 UITableViewCell 在编辑时不显示缩进
【发布时间】:2013-12-10 20:47:39
【问题描述】:

我在 iOS 7 上,有一个 UITableViewController,一个 UITableView(链接数据源和委托)并尝试使用编辑。我在 UIStoryboard 中使用带有 Dynamice Prototype 的自定义 UITableViewCell。当我单击编辑按钮(self.editButtonItem)时,您会看到名称更改为完成,但没有缩进图标(-图标)。从单元格滑动,我得到一个删除按钮。

这是我的代码:

self.navigationItem.leftBarButtonItem = self.editButtonItem;

// Override to support conditional editing of the table view.
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    // Return NO if you do not want the specified item to be editable.
    return YES;
}

// Override to support editing the table view.
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        // Delete the row from the data source
        [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
    }   
    else if (editingStyle == UITableViewCellEditingStyleInsert) {
        // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view
    }   
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    return UITableViewCellEditingStyleDelete;
}

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

我的所有内容都在 contentView 中

【问题讨论】:

  • 确保您的单元格的自定义内容已添加到单元格的contentView,而不是直接添加到单元格中。
  • 我添加了我的问题,看图。
  • 编辑按钮里有什么代码?

标签: ios iphone objective-c uitableview


【解决方案1】:
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{


    if (editingStyle == UITableViewCellEditingStyleDelete)
    {
        [arr removeObjectAtIndex:indexPath.row];
        [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationBottom];
    }
}



- (IBAction)editbtn:(id)sender {

    if (self.tableView.editing) {
        self.tableView.editing = NO;
        [edit setTitle:@"Edit" forState:UIControlStateNormal];
    }
    else{
        self.tableView.editing = YES;
        [edit setTitle:@"Done" forState:UIControlStateNormal];
    }
}

我认为这段代码对你有帮助。

【讨论】:

    【解决方案2】:

    在 UIViewController self.editButtonItem 不起作用,你需要创建一个自定义按钮。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-01
      • 2011-08-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多