2009-09-23 4 views
0

도구 모음에 NSArray을 재생성하고 테이블의 내용을 다시로드하려고하는 새로 고침 단추가 있습니다.UITableView가 섹션 및 내용을 다시로드하지 않습니다.

if (boolCondition) { 
    [self refreshTableDataSet]; 
    [self.tableView reloadSections:[NSIndexSet indexSetWithIndex:kTableSectionOfInterest] withRowAnimation:UITableViewRowAnimationFade]; 
} 

또는 : 테이블이 실패 새로 고침

if (boolCondition) { 
    [self refreshTableDataSet]; 
    [self.tableView reloadData]; 
} 

에 대해 다른 모든 시도를 내가 가지고 있는지하지만

. 때로는 효과가 있고 가끔은 그렇지 않습니다.

NSLog 문은 -tableView:cellForRowAtIndexPath:에 있는데이 방법을 사용할 때 알려드립니다. 새로 고침이 실패하면이 NSLog 문 출력이 표시되지 않습니다.

새로운 데이터가있을 때 테이블보기를 다시로드하는 것에 대해 누락 된 것이 있습니까?

편집-refreshTableDataSet 방법에서

: 내 테이블보기에서

- (void) refreshTableDataSet { 
    NSSortDescriptor *_objectTypeSorter = [[[NSSortDescriptor alloc] initWithKey:@"object.type" ascending:YES] autorelease]; 
    NSSet *_objectSet = [managedObjectContext fetchObjectsForEntityName:@"Object" withPredicate:[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"group.name like '%@'", [group name]]]]; 
    self.objects = [[[_objectSet allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObjects: _objectTypeSorter, nil]] retain]; 
} 

-tableView:cellForRowAtIndexPath: 방법 :

... 
Object *_object = [self.objects objectAtIndex:indexPath.row]; 
if (cell == nil) { 
    cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:CellIdentifier] autorelease]; 
} 
cell.textLabel.text = _object.name; 
cell.detailTextLabel.text = _object.type; 
cell.imageView.image = [UIImage imageNamed:@"GroupType.png"]; 
cell.accessoryView = [self imageViewForObjectDetailType:_object.type]; 
... 

나는 accessoryView하는 방법이 -imageViewForObjectDetailType, 단지 수익을 불렀다 a UIImageView :

return [[[UIImageView alloc] initWithImage:[UIImage imageNamed:@"GenericObjectDetailType.png"]] autorelease]; 

누락 된 메시지가 retain 및/또는 release입니까?

답변

1

확인해 보았지만, NSArray이 유지되어 있지 않고 tableview에 전달 된 경우 이와 같은 임의의 동작이 발생합니다.

은 당신이 머무르는 코드를 보면, 내가 먼저 눈에 뭔가 잘못 표시되지 않습니다 - 여기에 몇 가지 팁입니다

1.In :

self.objects = [[[_objectSet allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObjects: _objectTypeSorter, nil]] retain]; 

개체가 @propertyretain와 속성의 경우, 그러면 여기 다시 retain 할 필요가 없습니다. 왜 그것이 실패하더라도. 바로, 바로 경우 (셀 == 전무) 이전

UITableViewCell *cell = (UITableViewCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

: 당신의 cellForRowAtIndexPath:

2.In, 당신은 뭔가를해야합니까?

이 최대 여러 줄에

Object *_object = [self.objects objectAtIndex:indexPath.row]; 

4.Break에 배열에서 그것을 얻을하고 있는지 확인 NSLog 모든 반환 값을 볼 때 3.You는 NSLog에 개체의 값을 할 수 있습니다 새로 고침 할 때마다 모두 성공합니다.

self.objects = [[[_objectSet allObjects] sortedArrayUsingDescriptors:[NSArray arrayWithObjects: _objectTypeSorter, nil]] retain]; 

당신이 기대하는 것을 당신이 당신을 받고있다 인출 있는지 확인하려면이 옵션을 선택 5.Double :

NSSet *_objectSet = [managedObjectContext fetchObjectsForEntityName:@"Object" withPredicate:[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"group.name like '%@'", [group name]]]]; 

당신은 실패 새로 고침 당신에게 나쁜 수를 제공 있는지 여부를보기 위해 [_objectSet count]NSLog 수 있습니다.

희망이 도움이됩니다.

+0

NSArray 설정 방법을 보여주는 코드를 추가했습니다. 내가 뭔가 빠진 것 같니? 감사! –

+0

나는 잘못된 곳에서 나의'if (cell == nil)'테스트를 받았다. 나는 switch-case 트리를 가지며 각 case 블록으로 조건을 옮겨야 만했다. 당신의 철저한 아이디어에 감사드립니다. –

+0

좋은 sleuthing! – mahboudz

관련 문제