【问题标题】:How to change the text of a label after UITableViewCell re-orderUITableViewCell重新排序后如何更改标签的文本
【发布时间】: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


    【解决方案1】:

    我用下面的 for...loop 解决了这个问题

        for (int i = 0; i < numberOfRows; i++) 
        {
            [[profileItemsNSMArray objectAtIndex:i] setValue:[NSNumber numberWithInt:i + 1] forKey:@"profileItemsSongOrder"];
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 2016-07-07
      • 2022-07-29
      • 2019-05-20
      • 1970-01-01
      相关资源
      最近更新 更多