我有一個UITableView
放在編輯模式。iPhone - 如何添加最後一行在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
允許重新排列任何線路。我可以在「添加行」之後移動第一行,並將「添加行」移動到第一位置。
我該如何刪除「添加行」單元格上的排列按鈕,並防止其他行在這個下面?
或者是否有更好的方法來編碼?