0
我有一個自定義的UITableViewCell叫做CustomCell,它有一個UILabel,它應該顯示當前的索引號+ 1(這是一個要做的事情的隊列)。moveRowAtIndexPath cell numbering
我正在使用setEditing方法來允許用戶移動單元格,但我無法使用以下代碼正確編號單元格(按順序)。基本上我只是試圖訪問該方法參數傳遞的區域中的單元格,但數字只是簡單地返回無序。我在這裏做錯了什麼?
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
[queuedToDoArray moveObjectAtIndex:fromIndexPath.row toIndex:toIndexPath.row];
NSIndexPath *lowerIndexPath = (fromIndexPath.row < toIndexPath.row ? fromIndexPath : toIndexPath);
NSIndexPath *higherIndexPath = (fromIndexPath.row > toIndexPath.row ? fromIndexPath : toIndexPath);
//Update all the queue numbers in between moved indexes
for (int i = lowerIndexPath.row; i <= higherIndexPath.row; i++) {
NSIndexPath *currentIndexPath = [NSIndexPath indexPathForRow:i inSection:0];
CustomCell *currentCell = [todoTable cellForRowAtIndexPath:currentIndexPath];
[currentCell.queueNumber setText:[NSString stringWithFormat:@"%i", currentIndexPath.row + 1]];
}
}
而不是重新加載整個表,你可以重新加載受影響的行 – Paulw11
@ Paulw11好點,重新加載特定的行是一個更好的方法。 –