2012-02-23 12 views
1

私はカスタムセルを持つUITableViewを持っています。編集をタップすると、TableViewは編集モードになります。セルを移動して削除し、その結果をコアデータエンティティに保存することができます。セルの新しい順序は、Core Dataに保持され、すべて動作します。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]; 
} 

答えて

0

-Paul事前に

おかげで私はのために...ループ、以下でこれを解決し

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