2009-11-09 7 views
0

사이트 피드에서 읽고 UITableViewCell에 표시하는 작은 응용 프로그램을 작성했습니다. 사용자 정의보기 셀을 사용하고 내 UITableView 거꾸로 스크롤 매우 매끄럽지 않은 것처럼 스크롤에 망쳐 있습니다. 어떤 생각? 여기에 세포/데이터를 구축하지 세포 생성에, 초기화에 요청을 할 등 플러시 얻을로 dequeueReusableCellWithIdentifier 메소드를 호출 AFAIK 내있는 UITableViewCell에 대한 코드,iPhone UITableViewCell 성능 저하

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

    static NSString *CellIdentifier = @"CustomCell"; 

    CustomCell *cell = (CustomCell *) [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 
    if (cell == nil) { 
     //  cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 
     NSArray *topLevelObjects = [[NSBundle mainBundle] loadNibNamed:@"CustomCell" owner:nil options:nil]; 
     for(id currentObject in topLevelObjects) { 
      if([currentObject isKindOfClass:[UITableViewCell class]]) { 
       cell = (CustomCell *) currentObject; 
       break; 
      } 
     } 
    } 
    //MiceAppDelegate *AppDelegate = (MiceAppDelegate *)[[UIApplication sharedApplication] delegate]; 
    if(dataArray != nil) { 
     // 
     //NSArray *promoArray = (NSArray *) promotions; 
     NSDictionary *datadict = [self.dataArray objectAtIndex:indexPath.row]; 

     NSString *url = [datadict objectForKey:@"imageUrl"]; 
     NSString *title = [datadict objectForKey:@"title"]; 
     NSString *description = [datadict objectForKey:@"description"]; 

     NSString *newAddressPartOfURL = [url stringByReplacingOccurrencesOfString:@" " withString:@"+"]; 

     //NSLog([url stringByAddingPercentEscapesUsingEncoding:NSASCIIStringEncoding]); 

     NSURLResponse *urlResponse; 

     NSData *data = [NSURLConnection sendSynchronousRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:newAddressPartOfURL]] returningResponse:&urlResponse error:nil]; 

     // Configure the cell. 
     UIImage *urlImage = [[UIImage alloc] initWithData:data]; 

     // NSLog(@"%i",[imageView.image topCapHeight]); 
     cell.title.text = title; 
     cell.description.text = description; 
     cell.image.image = urlImage; 
     [urlImage release]; 
    } 
    return cell; 
} 

답변

3

셀이 그려지는 동안 동기 다운로드를 수행하면 분명히 불편한 스크롤이 발생할 것입니다. 다운로드가 진행되는 동안 asynchronous 호출로 해당 호출을 대체하고 일반 오브젝트로 데이터를 채울 수 있습니다. 다운로드가 완료되면 테이블 뷰에서 reloadData를 호출하십시오.