2011-10-19 2 views
1

저는 UITableView를 가지고 있으며 셀에 사용자 정의보기를 추가하고 있습니다. 그것은 단지 2 개의 셀로 뒤져 있습니다. 마치 위아래로 스크롤 할 때 나는 그것이 더듬 거리는 것을 볼 수 있습니다/이것은 (iPhone 4s에있는) 많이 뒤떨어졌습니다. 나는 앱 스토어 앱을 보았고 매우 복잡한 tableviewcell으로 스크롤하는 것이 부드럽다. 내가 뭔가 잘못하고 있는거야? 내가있는 UITableViewController를로드 할 때UITableView는 실제로 단지 2 셀로 뒤떨어져 있습니다.

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    int row = [indexPath row]; 


    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] autorelease]; 
     [cell setAccessoryType:UITableViewCellAccessoryDisclosureIndicator]; 


     UILabel *labelBarcode = [[UILabel alloc] initWithFrame:CGRectMake(80, 7, 150, 15)]; 
     [labelBarcode setFont:[UIFont fontWithName:@"Helvetica-Bold" size:16]]; 
     [labelBarcode setTag:10]; 

     UILabel *labelLength = [[UILabel alloc] initWithFrame:CGRectMake(80, 22, 150, 15)]; 
     [labelLength setFont:[UIFont fontWithName:@"Helvetica" size:14]]; 
     [labelLength setTag:11]; 

     UILabel *labelThickness = [[UILabel alloc] initWithFrame:CGRectMake(80, 37, 150, 15)]; 
     [labelThickness setFont:[UIFont fontWithName:@"Helvetica" size:14]]; 
     [labelThickness setTag:12]; 

     UILabel *labelDiameter = [[UILabel alloc] initWithFrame:CGRectMake(190, 22, 100, 15)]; 
     [labelDiameter setFont:[UIFont fontWithName:@"Helvetica" size:14]]; 
     [labelDiameter setTag:13]; 

     UILabel *labelCoating = [[UILabel alloc] initWithFrame:CGRectMake(190, 37, 100, 15)]; 
     [labelCoating setFont:[UIFont fontWithName:@"Helvetica" size:14]]; 
     [labelCoating setTag:14]; 

     UIImageView *thumbView = [[UIImageView alloc] initWithFrame:CGRectMake(4, 4, 65, 50)]; 
     [thumbView setContentMode:UIViewContentModeScaleToFill]; 
     [thumbView setTag:15]; 


     [[cell contentView] addSubview:thumbView]; 
     [[cell contentView] addSubview:labelBarcode]; 
     [[cell contentView] addSubview:labelLength]; 
     [[cell contentView] addSubview:labelThickness]; 
     [[cell contentView] addSubview:labelDiameter]; 
     [[cell contentView] addSubview:labelCoating]; 

     [thumbView release]; 
     [labelBarcode release]; 
     [labelLength release]; 
     [labelThickness release]; 
     [labelDiameter release]; 
     [labelCoating release]; 

    } 
    UILabel *labelBarcode = (UILabel *)[[cell contentView] viewWithTag:10]; 
    UILabel *labelLength = (UILabel *)[[cell contentView] viewWithTag:11]; 
    UILabel *labelThickness = (UILabel *)[[cell contentView] viewWithTag:12]; 
    UILabel *labelDiameter = (UILabel *)[[cell contentView] viewWithTag:13]; 
    UILabel *labelCoating = (UILabel *)[[cell contentView] viewWithTag:14]; 
    UIImageView *thumbView = (UIImageView *)[[cell contentView] viewWithTag:15]; 

    NSDictionary *pipe = [pipes objectAtIndex:row]; 


    NSString *stringBarcode = [pipe objectForKey:@"Barcode"]; 
    NSString *stringLength = [NSString stringWithFormat:@"Length: %@", [pipe objectForKey:@"Length"]]; 
    NSString *stringThickness = [NSString stringWithFormat:@"Wall: %@",[pipe objectForKey:@"Thickness"]]; 
    NSString *stringCoating = [NSString stringWithFormat:@"Coating: %@", [pipe objectForKey:@"Coating"]]; 
    NSString *stringDiameter = [NSString stringWithFormat:@"Diameter: %@",[pipe objectForKey:@"Diameter"]]; 


    [labelBarcode setText:stringBarcode]; 
    [labelLength setText:stringLength]; 
    [labelThickness setText:stringThickness]; 
    [labelDiameter setText:stringDiameter]; 
    [labelCoating setText:stringCoating]; 
    [thumbView setImage:[UIImage imageWithData:[pipe objectForKey:@"Thumbnail"]]]; 

    return cell; 
} 

지체 특히 발생합니다

여기 내 코드입니다. 내가 아무것도 할당 아니에요, 난 단지 (plist에서) 응용 프로그램이로드되고, 전체 애플 리케이션 메모리 소비가 1.56 메가 바이트에있는 데이터를 할당합니다.

답변

0

크기 조정의 일부 유형을 수행하는 이미지보기가있는 것과 관련된 비슷한 문제가있었습니다. 먼저 확인해 보겠습니다. thumbView가 크기 조정을 수행하는 경우, 스크롤하는 동안 자체적으로 테이블이 지연 될 수 있습니다. 이 경우 크기를 조정 한 이미지를 미리 렌더링 해 볼 수 있습니다. 나는 여기에 단지 두 개의 셀만 있으면 실제로 어떤 세포도 테이블에서 꺼내지 못한다고 가정하고 있습니다. 이미지를 만드는 시간에 대한 다른 대답은 셀을 다시 사용할 때만 여러 번 수행하는 경우에만 적용됩니다.

0

이 줄의 코드 :

[thumbView setImage:[UIImage imageWithData:[pipe objectForKey:@"Thumbnail"]]]; 

이 차단되고 그것이 얼마나 많은 데이터에 따라 많은 시간이 걸릴 수 있습니다. 이 작업을 배경 스레드에서 수행하고 (아마도 NSOperation을 통해) 이미지가 준비 될 때 행을 다시로드하십시오.

0

시도 재사용 조건의 내부

[thumbView setImage:[UIImage imageWithData:[pipe objectForKey:@"Thumbnail"]]];

퍼팅.

+0

각 파이프가 아마도 다른 축소판을 가지고 있기 때문에 이는 적절하지 않습니다. 여전히 코드를 메인 스레드에서 실행하고 있는데, 이것은 성능을 죽일 것입니다. –

+0

Ahh ok - 코드를 잘못 읽었습니다. 실수였습니다. thumbview가 항상 동일하다는 인상을 받았습니다. – barfoon

관련 문제