2014-03-03 3 views
0

저는 개발 중이며 iOS 앱과 UITableView는 다소 느립니다. 슬로우 스크롤에 대한 모든 가능한 이유를 알고 싶습니다. 스토리 보드에서 프로토 타입 셀을 사용하고 있으며 이미지가 없습니다.TableView 느린 스크롤

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    static NSString *identifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier]; 
    if (cell == nil) 
     cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier]; 

    Classification *classification = [classifications objectAtIndex:indexPath.row]; 
    UILabel *teamLabel = (UILabel *) [cell viewWithTag:101]; 
    [teamLabel setText:[classification team]]; 
    [cell setBackgroundColor:[UIColor clearColor]]; 
    return cell; 

} 

또한 시뮬레이터에서 부드럽게 실행됩니다. 텍스트 데이터와 스레드 등에있을 필요가 이미지에 대한 하나를 채우기 위해,

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

사용이 분리있는 UITableViewCell 객체 하나를 : 나는 아이 패드 2

+0

tableView의 구현을 게시 할 수있는 경우 : cellForRowAtIndexPath : method ... 위대한 것입니다 –

+0

은 웹 서비스에서 오는 데이터입니까? –

+0

이 (가) 편집되었습니다. 네, 웹 서비스에서 왔습니다. 데이터를 사용자 지정 개체로 구문 분석 한 다음 배열에 저장합니다. tableview 해당 배열에서 읽는 중입니다. –

답변

0

이 비동기 데이터를 다운로드 사용하고 있습니다 내 프로젝트에서 dispatch_async, 예를 들어 :

if (imageUrl.length > 0) 
     { 
      NSString *completeURL = @""; 
      completeURL = [completeURL stringByAppendingString:kPROFILE_IMAGE_URL]; 
      completeURL = [completeURL stringByAppendingString:@"/2/"]; 
      completeURL = [completeURL stringByAppendingString:imageUrl]; 
      completeURL = [completeURL stringByAppendingString:@".png"]; 

      NSString *fileName = [NSString stringWithFormat:@"%@.png", imageUrl]; 
      NSString* path = GetMediaFolder(); 
      BOOL imageExists = [[NSFileManager defaultManager] fileExistsAtPath:[path stringByAppendingPathComponent:fileName]]; 

      if (imageExists) 
      { 
       // NSLog(@"Image exists"); 
       // Update UI 

       dispatch_async(dispatch_get_main_queue(),^
       { 
        UITableViewCell *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath]; 

        UIImageView *imageView = (UIImageView*)[updateCell viewWithTag:kTAG_IMAGE]; 
        imageView.image=[UIImage imageWithContentsOfFile:[path stringByAppendingPathComponent:fileName]]; 
        imageView.layer.cornerRadius = 23.0; 
        imageView.layer.borderColor = (__bridge CGColorRef)([UIColor clearColor]); 
        imageView.layer.borderWidth = 1.0; 
        imageView.clipsToBounds = YES; 
        imageView.contentMode = UIViewContentModeScaleAspectFill; 

        [updateCell setNeedsLayout]; 
       }); 
      } 
      else 
      { 
       // NSLog(@"Image not exists"); 
       // Download The Image 

       dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^
       { 
        NSURL *imageURL=[NSURL URLWithString:completeURL]; 
        NSData *image=[NSData dataWithContentsOfURL:imageURL]; 
        [image writeToFile:[path stringByAppendingPathComponent:fileName] atomically:YES]; 

        // Update UI 
        dispatch_async(dispatch_get_main_queue(),^
        { 
         UITableViewCell *updateCell = (id)[tableView cellForRowAtIndexPath:indexPath]; 

         UIImageView *imageView = (UIImageView*)[updateCell viewWithTag:kTAG_IMAGE]; 
         imageView.image=[UIImage imageWithContentsOfFile:[path stringByAppendingPathComponent:fileName]]; 
         imageView.layer.cornerRadius = 23.0; 
         imageView.layer.borderColor = (__bridge CGColorRef)([UIColor clearColor]); 
         imageView.layer.borderWidth = 1.0; 
         imageView.clipsToBounds = YES; 
         imageView.contentMode = UIViewContentModeScaleAspectFill; 

         [updateCell setNeedsLayout]; 
        }); 
       }); 
      } 
     } 
    } 
    return cell; 

편집 1 :

이미지를 사용하지 않는 것을 볼 수 있습니다. 다운로드가 끝나면 (이미지 다운로드, 임시 데이터 및 다운로드 된 데이터 대신) 모든 데이터를 비동기식으로 다운로드하고 새로운 UITableViewCell으로 채워야합니다.

+0

필자의 경우에는 그다지 적용되지 않는다고 생각합니다. 웹 서비스를 작성한 후 데이터를 다운로드 한 다음 사용자 지정 개체를 메모리에 저장합니다. –

+0

UITableView에서 다운로드 한 데이터를 사용하면 문제가되지 않습니다. 먼저 데이터를 다운로드하지 말고 기다렸다가 채우십시오. –

관련 문제