데이터가 변경된 후 UITableView
에있는 셀을 어떻게 다시로드 할 수 있는지 조금 혼란 스럽습니다. 특히 내가 가지고있는 혼란은 새로운 데이터가 현재 표시되는 것보다 더 많거나 적은 섹션을 가질 수 있다는 것입니다. reloadSections:withRowAnimation:
방법이 있다는 것을 알고 있지만 1 : 1 교체가 필요합니다. 그 곳에서 또는 없을 수도 있습니다.얼마나 많은 섹션이 있을지 모를 때 어떻게 UITableView의 데이터를 다시로드합니까?
나는 단지 UITableView
에게 모든 것을 스크랩하고 처음으로 다시로드하라고 말하고 싶습니다. 나는 누군가가 이것에 대해 밝히고있는 것에 감사 할 것입니다.
미리 감사드립니다. 다음은 UPDATE
는
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell"];
NSLog(@"%@", cell);
if (cell == nil) {
NSLog(@"%d; %d", indexPath.section, vehicle.inventoryCategoriesCount);
if (indexPath.section < vehicle.inventoryCategoriesCount) {
NSLog(@"Grouped cell");
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"Cell"] autorelease];
NSString *model = [[[vehicle.inventory filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"category == %@", [vehicle.inventoryCategories objectAtIndex:indexPath.section]]] valueForKeyPath:@"@distinctUnionOfObjects.model"] objectAtIndex:indexPath.row];
cell.textLabel.text = model;
cell.detailTextLabel.text = [NSString stringWithFormat:@"%d", [[vehicle.inventory filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"model == %@", model]] count]];
cell.selectionStyle = UITableViewCellSelectionStyleNone;
} else {
NSLog(@"Remove cell");
cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"Cell"] autorelease];
cell.textLabel.text = @"Remove an Item";
cell.textLabel.textColor = [UIColor redColor];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
}
NSLog(@"Adding a cell");
return cell;
}
흠, 내가 데이터를 얻을 그것을 구문 분석하고 배열을 업데이트 한 후에 내가 그 메소드를 호출하고 볼 수 있지만, 그것의 세포를 바꾸지 않아. 테이블을 채우는'MSMutableArray'를 가지고 있고 그 객체는'category'와'model'이라는 속성을 가지고 있습니다. 'category'는 섹션이고,'model'은 객체를 그룹화하고 각/모델의 수를 표시하는 데 사용됩니다. 지금, 나는 "add"코드를 만들고 있는데, 변화하고있는 모델 그룹이 그것의 카운트를 업데이트하지 않는다는 것만 제외하면 작동해야한다. 다소 실망 스럽다 ... – Gup3rSuR4c
실제로, 더 많은 테스트를 할 때, - (UITableViewCell *) tableView : (UITableView *) tableView cellForRowAtIndexPath : (NSIndexPath *) indexPath'가 호출됩니다. 이전 생성에서 셀을 대기열에 추가하지 않습니다. 그래서 내가 잘못하고있는거야? – Gup3rSuR4c
'reloadData'를 호출하면 모든 데이터 소스 메소드 (numberOfSections, cellForRowAtIndexPath 등)가 다시 호출되므로 올바르게 업데이트 된 값을 반환해야합니다. 그렇다면 여기서 재사용 가능한 셀을 다시 대기열에 추가해야합니다. – jhabbott