1
我有一個帶有自定義單元格的UITableView。當我點擊編輯時,TableView會進入編輯模式。我可以移動單元格並刪除它們,並將結果保存到核心數據實體。核心數據中保留了單元格的新順序,這一切都有效。如何在UITableViewCell重新訂購後更改標籤的文本
但是我希望在移動之後或點擊「完成」之後,反映出單元格的新位置。無論標籤被移動到什麼位置,標籤中的值始終是行+1。我如何重新申請
實現此目標的最佳方法是什麼?
在此先感謝
- 保羅
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
{
ProfileItems *profileItems = [ingredients objectAtIndex:fromIndexPath.row];
// NSLog(@"profileItems: %@", profileItems);
[ingredients removeObjectAtIndex:fromIndexPath.row];
[ingredients insertObject:profileItems atIndex:toIndexPath.row];
NSInteger start = fromIndexPath.row;
NSLog(@"start: %d", start);
NSInteger end = toIndexPath.row;
NSLog(@"end: %d", end);
// Update Core Data to reflect the cell's new position in the TableView
profileItems.profileItemsSongOrder = [NSNumber numberWithInteger:end + 1];
// This won't work becuase there is no cell referenced in here. Do I have to point to it again? If so how?
cell.profileItemsSongNumberLabel.text = [NSString stringWithFormat:@"%@",profileItems.profileItemsSongOrder];
}