【发布时间】:2011-03-27 16:02:23
【问题描述】:
我有一个 UITableView 处于编辑模式。
self.tableView.editing = YES;
在这个表格视图中,我在自定义单元格中显示了一些行,我想在最后添加一个允许用户添加项目(使用另一个视图)。
所以我写了几行:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return "number of lines" + 1;
}
- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath {
return YES;
}
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
if(indexPath.row+1 != [tableView numberOfRowsInSection:0]) {
return UITableViewCellEditingStyleDelete;
}
else {
return UITableViewCellEditingStyleInsert;
}
}
- (void) tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
if (indexPath.row + 1 == [tableView numberOfRowsInSection:0]) {
cell.textLabel.text = @"Add a line...";
}
else {
do the stuff in the custom cell
}
}
这样做,UITableView 允许重新排列任何行。我可以在“添加行”之后移动第一行,并将“添加行”移动到第一个位置。
如何删除“添加行”单元格上的排列按钮并防止其他行进入此行?
或者有更好的编码方式吗?
【问题讨论】:
标签: iphone uitableview editing