정보를 다른보기에서 삽입 한 후에 업데이트해야하는 tableView가 있습니다. 내가 수행하는 경우iPhone SDK : 새 행으로 UITableView 삽입 및 업데이트
[self.tableView reloadData];
내가 다른보기에서 더 많은 정보를 삽입하고 테이블을 다시로드하려고 바로 다음에, 모든 현재 보이는 행이 복제됩니다. 나는 응용 프로그램을 시작할 때 즉
, 내가 가진 :
tableView:
Row 1
Row 2
그리고 나는 또한 표에 표시됩니다 몇 가지 정보를 입력하고 갑자기 내가 가진 :
tableView
Row 1
Row 2
Row 3 <- info I just added
Row 1
Row 2
내 numberOfRowsInSection 구현은 다음과 같습니다.
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [ItemsController sharedItemsController].count;
}
내 cellForRowAtIndexPath 구현 모양 다음과 같이하십시오 :
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
ItemsController* controller = [ItemsController sharedItemsController];
NSMutableArray* recentItems = controller.listOfRecentItems;
CustomCell *cell = nil;
NSUInteger row = [indexPath row];
if(row < recentItems.count)
{
Items* item = [recentItems objectAtIndex:row];
if(recentCellData == nil)
recentCellData = [[NSMutableDictionary alloc] initWithCapacity:[indexPath length]];
if([recentCellData count] > 0)
cell = [recentCellData objectForKey:[NSString stringWithFormat:@"%d", row]];
if (cell == nil) {
UIViewController * view1 = [[UIViewController alloc] initWithNibName:@"CustomCell" bundle:nil];
cell = (CustomCell*)[view1 view];
[recentCellData setObject:cell forKey:[NSString stringWithFormat:@"%d",row]];
}
// do some other stuff here
}
// Set up the cell
return cell;
}
테이블을 업데이트하고 현재 보이는 행이 중복되지 않도록하는 가장 좋은 방법은 무엇입니까? 모든 도움을 미리 보내 주셔서 감사합니다!
질문에 tableView : numberOfRowsInSection : 메서드의 구현을 포함해야하는 것처럼 보입니다. – dstnbrkr
질문에 그 정보를 추가했습니다. 감사! – Jeff