【发布时间】:2012-02-23 13:19:04
【问题描述】:
我有一个带有自定义单元格的 UITableView。当我点击编辑时,TableView 进入编辑模式。我可以移动单元格,删除它们,并将结果保存到核心数据实体。新的单元格顺序保留在 Core Data 中,一切正常。
但是,我希望在移动后或点击“完成”后反映单元格的新位置。标签中的值始终是行 + 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];
}
【问题讨论】:
标签: iphone ios5 xcode4.2 uitableview