【发布时间】: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