2010-08-07 5 views
0

문제가있는 표가 다른 표 컨트롤러에서 푸시되고이 표에 단 하나의 섹션 만 있으며 사용자 정의 셀을 사용하고 있습니다.UITableViewController numberOfRowsInSection은 실제 행 수에 영향을주지 않습니다.

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 
NSInteger numberOfRows; 
if ([imagesArray count] == 0) { 
    numberOfRows = 0; 
} 
else { 
    if ([imagesArray count] % 4 == 0) { 
     numberOfRows = [imagesArray count]/4; 
    } 
    else { 
     numberOfRows = ([imagesArray count]/4) + 1; 
    } 
} 
NSLog(@"numberOfRowsInSection: %d", numberOfRows); 
return numberOfRows; 
} 

여기 로그는 항상 행의 예상 번호를 인쇄 : 여기 numberOfRowsInSection에 대한 코드입니다. 여태까지는 그런대로 잘됐다. 이제 cellForRowAtIndexPath 살펴 보자 :

cellForRowAtIndexPath: <NSIndexPath 0x5a4f2c0> 2 indexes [0, 0] 
cellForRowAtIndexPath: <NSIndexPath 0x5a4f2c0> 2 indexes [0, 1] 
cellForRowAtIndexPath: <NSIndexPath 0x5a4f2c0> 2 indexes [0, 2] 
cellForRowAtIndexPath: <NSIndexPath 0x5a4f2c0> 2 indexes [0, 3] 
cellForRowAtIndexPath: <NSIndexPath 0x5a4f2c0> 2 indexes [0, 4] 

을 아무리 numberOfRowsInSection에 의해 반환되는 값이 무엇인지, 그것이 제로 또는 100 여부 :

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(@"cellForRowAtIndexPath: %@", [indexPath description]); 

    ImageTableCell *cell = (ImageTableCell *)[tableView dequeueReusableCellWithIdentifier:@"4ImagesCell"]; 
    if (cell == nil) { 
      cell = [[[ImageTableCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"4ImagesCell"] autorelease]; 
    } 
    return cell; 
} 

여기 콘솔은 "항상"은 다음 없다 인쇄 테이블은 항상 5 행을 요구합니다! 심지어 현재 조건 대신 numberOfRowsInSection에 정적 ​​숫자를 반환하려고 시도했지만 실제로 셀 수에 차이가 없습니다!

나를 미치게 만드는 원인은 cellForRowAtIndexPath로 이동하기 전에 테이블이 numberOfRowsInSection 메소드에 도달한다는 것입니다!

내가 생각할 수있는 유일한 문제는이 테이블 컨트롤러가 다른 UITableViewController에서 푸시되지만이 테이블에있는 동안 이전 테이블의 numberOfRowsInSection 메서드가 체크되지 않는다는 것입니다. 숫자를 수정하려고 시도하기까지했습니다. 부모 테이블의 행을 행운없이.

정보가 누락 된 경우 알려주십시오. 프로젝트가 복잡해지고이 문제에 대한 다른 관련 정보는 생각할 수 없습니다.

답변

2

테이블 뷰는 보이는 셀만로드하기 때문입니다. tableview를 스크롤 해 보셨습니까? 나는 당신이 그렇게한다면, 더 많은 줄이로드되는 것을 볼 수있을 것이다. ...

+0

오, 그래, 나는 이것을 다음날 알아 냈다. 다음에 나는 졸리는 동안 코드 작성/디버깅을 중단해야한다. 당신의 친절한 대답에 대해 Dave와 Ankur에게 감사드립니다. – Motasim

0

대신 이렇게 로깅 해 볼 수 있습니까?

NSLog(@"cellForRowAtIndexPath: (section:%@, row:%@)", [indexPath section], [indexPath row]); 

나는 우리가 설명하는 방법의 출력이 당신이 생각하는 바가 아닐 수도 있다고 생각합니다.

관련 문제