我有一个带自定义单元格的UITableView。当我点击编辑时,TableView会进入编辑模式。我可以移动单元格并删除它们,并将结果保存到核心数据实体。新的单元格顺序保留在Core Data中,一切正常。
但是我希望在移动之后或者在点击“完成”之后反映单元格的新位置。无论移动到何处,标签中的值始终为行+ 1。我如何重新补充
实现这一目标的最佳方法是什么?
提前致谢
-Paul
- (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];
}
答案 0 :(得分:0)
我通过以下方式解决了这个...循环
for (int i = 0; i < numberOfRows; i++)
{
[[profileItemsNSMArray objectAtIndex:i] setValue:[NSNumber numberWithInt:i + 1] forKey:@"profileItemsSongOrder"];
}