2009-08-25 4 views
0

IB에서 만든 사용자 지정 UITableViewCell이 있습니다. 코코아 콩로드 이러한 세포의 인스턴스와 jQuery과를 채우려면, 나는 다음과 같은 코드를 사용합니다UITableViewCell 프레임의 NaN 값이

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 

    static NSString *CellIdentifier = @"overviewCell"; 

    HOStoreOverviewCell *cell = (HOStorwOverviewCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     UIViewController *c = [[UIViewController alloc] initWithNibName:@"HOStoreOverviewCell" bundle:[NSBundle mainBundle]]; 
     cell = (HOStoreOverviewCell *)c.view; 
    } 

    HOStore *itemAtIndex = (HOStore *)[self.infoController storeInListAtIndex:indexPath.row]; 

    cell.storeName.text = itemAtIndex.name; 
    cell.distance.text = [itemAtIndex niceDistance]; 
    cell.hours.text = [itemAtIndex.currentHour niceHours]; 
    NSLog(@"%@", cell); 

    return cell; 
} 

HOStoreOverviewCell 내 사용자가 NIB에있는 UITableViewCell, 그리고 포함 된 세 UILabels (StoreName이, 거리 및 시간) . 따라서이 코드는 재사용 가능한 셀을 큐에서 빼내려고 시도하고, 그렇지 않으면 NIB에서로드하여 새 셀을 만듭니다. 그런 다음 UILabels의 텍스트를 배열의 항목 (HOStore 's)에서 정보의 관련 비트로 설정합니다. 꽤 표준적인 것들.

내 문제는 다음과 같습니다. 대부분의 셀이 제대로 표시되지만 현재는 안정적으로 재현 할 수 없습니다. UITableView가 셀을 "놓칠"수 있습니다. 예를 들어 10 번째 셀이 표시됩니다. 및 12 번째 세포가 아닌 11 번째 세포. 대신 11 번째 셀이 있어야하는 빈 곳이 있고이 부분을 두드리면 아무 효과가 없습니다. 빈 자리 아래 아무 곳이나 두드리는 것은 나에게 didSelectRowAtIndexPath : indexPath 위임 (indexPath.row가 항상 누락 된 색인 (예 : 11)으로 설정된) 메소드를 제공합니다. 두 번째 줄의 프레임에

2009-08-26 00:22:29.292 AppName[380:207] <HOStoreOverviewCell: 0x42c9880; baseClass = UITableViewCell; frame = (0 660; 320 66); autoresize = W; layer = <CALayer: 0x42c9a60>> 
2009-08-26 00:22:30.331 AppName[380:207] <HOStoreOverviewCell: 0x42c9880; baseClass = UITableViewCell; frame = (0 nan; 320 66); autoresize = W; layer = <CALayer: 0x42c9a60>> 
2009-08-26 00:22:32.138 AppName[380:207] <HOStoreOverviewCell: 0x42c71d0; baseClass = UITableViewCell; frame = (0 594; 320 66); autoresize = W; layer = <CALayer: 0x42c73b0>> 

참고 유모 다음 NSLog 출력 (발췌)을 볼 때

문제의 뿌리가 나타납니다. 이것은 cellForRowAtIndexPath : "blank"셀이 스크롤 할 때 나타나는 indexPath 콜백에 해당합니다.

이 문제의 원인에 대한 아이디어가 있으십니까?

답변

1

코드의이 섹션은 호기심 :

if (cell == nil) { 
      UIViewController *c = [[UIViewController alloc] initWithNibName:@"HOStoreOverviewCell" bundle:[NSBundle mainBundle]]; 
      cell = (HOStoreOverviewCell *)c.view; 
    } 

왜 여기에 일반적인 UIViewController을 allocing입니까? 아무도 그걸 풀어주지 않을 것이므로, 저에게 메모리 누출처럼 보입니다.

당신은 당신이 펜촉에서 테이블 셀을로드하는 경우 겪게 될 것이다이

if (cell == nil) 
{ 
    cell = [[[HOStoreOverviewCell alloc] initWithFrame:CGRectZero reuseIdentifier:cellIdentifier] autorelease]; 
} 

귀하의 성능과 같은 많은 일을해야한다. 코드에 할당하는 것이 훨씬 낫습니다. Apple Dev 포럼에서이 내용을 몇 번 읽었으며 Nibs를 사용하면 테이블이 "느려지 게"됩니다.