2011-02-16 4 views
1


이것은 내 cellForRowAtIndexPath입니다.테이블보기의 반복 된 셀

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Maledetta"]; 
if (cell == nil) { 
    UIViewController *c; 
    if (!IS_IPAD) c = [[UIViewController alloc] initWithNibName:@"NewsRow" bundle:nil]; 
    else c = [[UIViewController alloc] initWithNibName:@"NewsRow_ipad" bundle:nil]; 
    cell = (NewsRowController*)c.view; 

    if ([titleArray count] > 0) { 
     [(NewsRowController*)cell setCellDataWithName:[titleArray objectAtIndex:indexPath.row] 
               andDate:[descArray objectAtIndex:indexPath.row] 
                day:[dayArray objectAtIndex:indexPath.row] 
               month:[monthArray objectAtIndex:indexPath.row]]; 
    } 
    [c release]; 
} 
return cell; 
} 

내가 왜 단지 4 행을 보여 주며, 그 다음에 네 번째 다른 시간은 10 시까 지 처음으로 반복됩니다.

+-----------------------+ 
| A 
+-----------------------+ 
| B 
+-----------------------+ 
| C 
+-----------------------+ 
| D 
+-----------------------+ 
| A (repeated) 
+-----------------------+ 
| B (repeated) 
+-----------------------+ 
| C (repeated) 
+-----------------------+ 
| D (repeated) 
+-----------------------+ 
| A (repeated) 
+-----------------------+ 
| B (repeated) 
+-----------------------+ 

[titleArray count]10는 동일하다. kCustomCellID이 맞습니다.

감사합니다.

+0

디버거를 단계별로 실행하고 값을 한 번에 하나씩 확인하는 것이 좋습니다. 필요하다면 "po 객체"를 사용하여 객체의 원시 세부 사항을 인쇄 할 수 있습니다. – clifgriffin

답변

5

테이블의 셀 대기열에 셀이없는 경우에만 셀을 채우고 있습니다. 그것이 발견되면 indexPath.row의 해당 값에 대한 내용으로 덮어 쓰지 않습니다.

대신을 시도

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Maledetta"]; 
if (cell == nil) { 
    UIViewController *c; 
    if (!IS_IPAD) c = [[UIViewController alloc] initWithNibName:@"NewsRow" bundle:nil]; 
    else c = [[UIViewController alloc] initWithNibName:@"NewsRow_ipad" bundle:nil]; 
    cell = (NewsRowController*)c.view; 
    [c release]; 

} 

if ([titleArray count] > 0) { 
     [(NewsRowController*)cell setCellDataWithName:[titleArray objectAtIndex:indexPath.row] 
               andDate:[descArray objectAtIndex:indexPath.row] 
                day:[dayArray objectAtIndex:indexPath.row] 
               month:[monthArray objectAtIndex:indexPath.row]]; 
    } 
    return cell; 
} 

또한, [titleArray 수]의 체크 아마 중복입니다. 이 테이블에 대한 섹션의 셀 수를 줄 때 사용하고 있습니까? 그것이 0이라면, 여기 도착하지 않을 것입니다.

+0

대단한 !!! 맥주 마실 래? !!! – elp

+0

@Paska - 좋은 소리! –

+0

와우 ... tht는 일했다 :) :) 고마워 많은 친구 :) –

0

[tableView dequeueReusableCellWithIdentifier:@"Maledetta"]을 호출하면 테이블보기에서 더 이상 화면에 표시되지 않는 캐시의 셀을 찾습니다. 그것은 당신의 세포를 찾아 대신 사용합니다. 셀에 -prepareForReuse을 구현 한 다음 -cellForRowAtIndexPath: 구현에 else 절을 추가하여 재사용 된 셀을 처리하십시오.