2011-01-21 4 views
0

이 문제를 해결할 생각이 있습니까? cellForRowAtIndexPath 및 NSBundle mainBundle의 문제점

는 respectly 정확하고 잘못된 방법입니다 :
alt text alt text

이 작동되는 코드 :

- (UITableViewCell *)[...] cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    @try { 
     newsRow = ((NewsRowController *)[tableView dequeueReusableCellWithIdentifier:@"cell"]); 
     if (newsRow == nil) { 
      if ([[Device GetModel] isEqualToString:@"iPad Simulator"] || 
       [[Device GetModel] isEqualToString:@"iPad"]) 
       [[NSBundle mainBundle] loadNibNamed:@"NewsRow_ipad" owner:self options:nil]; 
      else [[NSBundle mainBundle] loadNibNamed:@"NewsRow" owner:self options:nil]; 

      if ([tableArray count] > 0) 
       [newsRow setData:[tableArray objectAtIndex:indexPath.row]]; 
     }  
    } 
    @catch (NSException * e) { 
     NSLog(@"a!!!!!"); 
    } 
    return newsRow; 
} 

...하지만 때문에 내 3g 장치에 그것의 천천히나는 위/아래로 테이블을 스크롤한다 나는이 방법으로 코드를 변경했다. viewDidLoad에 Device check를 삽입하고 그것을에 전달했다. 10 :

NSArray *cRow; 
@property (nonatomic, retain) NSArray *cRow; 
[...] 
@syntetize cRow; 

- (void)viewDidLoad { 
[...] 
    if ([[Device GetModel] isEqualToString:@"iPad Simulator"] 
     || 
     [[Device GetModel] isEqualToString:@"iPad"]) 
     cRow = [[[NSBundle mainBundle] loadNibNamed:@"NewsRow_ipad" owner:self options:nil] retain]; 
     else cRow = [[[NSBundle mainBundle] loadNibNamed:@"NewsRow" owner:self options:nil] retain]; 
[...] 
} 

- (UITableViewCell *)[...] cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    @try { 
     newsRow = ((NewsRowController *)[tableView dequeueReusableCellWithIdentifier:@"cell"]); 
     if (newsRow == nil) { 

      // 
      // ADDED CODE. 
      // 
      newsRow = [cRow objectAtIndex:0];  
      // 

      if ([tableArray count] > 0) 
       [newsRow setData:[tableArray objectAtIndex:indexPath.row]]; 
     }  
    } 
    @catch (NSException * e) { 
     NSLog(@"a!!!!!"); 
    } 
    return newsRow; 
} 

이제 테이블에 한 행만 표시됩니다. 스크롤하면 행이 변경되지만 한 행만 표시됩니다 ...
alt text
문제점 :

어떤 도움이 필요합니까?

덕분에, 당신이 dequeueReusableCellWithIdentifier를 호출이 경우

답변

1

: 대기열에서 제거 할 수있는 세포가 없기 때문에 당신은 다시 전무를 얻을 것이다. nil 셀을 가져올 때마다 nib를로드해야합니다. 그렇지 않으면 첫 번째 테이블 다음에 테이블에 셀을 추가하지 않습니다.

GetModel을 호출하는 것이 속도가 느린 경우 viewDidLoad에서 호출하여 나중에 사용하기 위해 저장할 수 있습니다.

각 셀에 그리는보기의 양 때문에 테이블이 부드럽게 스크롤되지 않는 것 같습니다. 배경이 항상 단색이면 셀이나 불투명도에 추가 할 모든 뷰를 확인해야합니다. 이미지 나 그라디언트 배경이 필요한 경우 셀을 모두 한 번에 볼 수 있습니다. 여기 애플은 좋은 방법을 가지고 있습니다 : TableViewSuite. 특히 TimeZoneView 파일을 체크 아웃하십시오.

+0

좋아요, 어떻게 문제를 해결할 수 있습니까 ??? – elp

+0

펜촉을로드하는 코드를 tableView : cellForRowAtIndexPath :로 다시 옮길 수 있습니다. iPad에서 viewDidLoad를 사용하지 않는 경우 BOOL을 저장할 수 있습니다. 그 후 스크롤이 여전히 느린 경우 펜촉으로 만든 셀 대신 Apple에서 만든 것처럼 UITableViewCell의 하위 클래스를 만듭니다. – criscokid

+0

완벽 그리고 루프에 사용할 var에 [[NSBundle mainBundle] loa ...]를 설정하는 방법이 있습니까? – elp

관련 문제