2012-02-23 3 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

- 폴 사전에

덕분에 나는 중 ... 루프를 다음과 같이이 문제를 해결

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