2012-04-06 3 views
0

UIScrollView이 포함 된 UITableViewCell이 있습니다. UIScrollView에는 각 행에 대해 다른 수의 UIImageViews이 있습니다. 일부 행에는 스크롤보기에 5 개의 이미지가 있고 일부 행에는 스크롤보기에 15 개의 이미지가 있습니다. 각 행에있는 UIImageViews의 수가 서로 다르므로 각 행을 그릴 때마다 새로운 UIImageViews을 할당해야합니다. 이것은 분명히 내 UITableView의 스크롤 성능에 부정적인 영향을 미치고 있습니다. UITableView 스크롤을 개선하기 위해이를 어떻게 해결할 수 있습니까?iPhone - 각 셀에 UIImageViews의 UIScrollView가있는 UITableView의 성능이 좋지 않음

또한 Instruments의 Time Profiler를 사용하여 [tableView dequeueReusableCellWithIdentifier:MyIdentifier]이라는 메서드 호출이 비정상적으로 느린 것으로 나타났습니다. 도움이 문제를 지적합니까?

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
static NSString *MyIdentifier = @"HuddleTableCell"; 

HuddleListItemTableViewCell *cellToReturn = [tableView dequeueReusableCellWithIdentifier:MyIdentifier]; 
if (cellToReturn == nil) { 
    [[NSBundle mainBundle] loadNibNamed:@"HuddleListItemTableViewCell" owner:self options:nil]; 
    cellToReturn = cell; 

    UILabel *badgeLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 50, 50)]; 
    badgeLabel.font = [UIFont boldSystemFontOfSize:16]; 
    badgeLabel.numberOfLines = 2; 
    badgeLabel.textAlignment = UITextAlignmentCenter; 
    badgeLabel.textColor = [UIColor whiteColor]; 
    badgeLabel.backgroundColor = [UIColor clearColor]; 
    [cellToReturn.attendee4Image addSubview:badgeLabel]; 
    cellToReturn.othersOverlayLabel = badgeLabel; 
    [badgeLabel release]; 
    cellToReturn.heartHolderView.layer.cornerRadius = 5; 

    cellToReturn.heartHolderView.colors = [NSArray arrayWithObjects:(id)[[UIColor colorWithRed:.29 green:.39 blue:.57 alpha:1.0] CGColor],(id)[[UIColor colorWithRed:.19 green:.22 blue:.36 alpha:1.0] CGColor], (id)[[UIColor colorWithRed:.102 green:.122 blue:.17 alpha:1.0] CGColor], nil]; 
    cellToReturn.heartHolderView.colors = [NSArray arrayWithObjects:(id)[UIColorFromRGB(0x4A59A8) CGColor], nil]; 
    cellToReturn.heartHolderView.layer.cornerRadius = 5.0; 

    UIView *polaroidView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 37, 39)]; 
    polaroidView.layer.shadowColor = [UIColor blackColor].CGColor; 
    polaroidView.layer.shadowOpacity = 0.3; 
    polaroidView.layer.shadowRadius = 1; 
    polaroidView.layer.shadowOffset = CGSizeMake(5.0f, 5.0f); 
    polaroidView.backgroundColor = [UIColor whiteColor]; 
    UIImageView *img = [[UIImageView alloc] initWithFrame:CGRectMake(4, 4, 29, 29)]; 
    [polaroidView addSubview:img]; 
    [cellToReturn.organizerImage addSubview:polaroidView]; 
    cellToReturn.polaroidView = polaroidView; 
    cellToReturn.polaroidImageView = img; 
    [img release]; 
    [polaroidView release]; 

    cellToReturn.gradientView.colors = [NSArray arrayWithObjects:(id)[[UIColor whiteColor] CGColor],(id)[[UIColor colorWithRed:.96 green:.96 blue:.96 alpha:1.0] CGColor],(id)[[UIColor colorWithRed:.85 green:.85 blue:.85 alpha:1.0] CGColor], nil]; 

    cellToReturn.votingTimerLabel.textColor = UIColorFromRGB(0x616163); 
    cellToReturn.eventDateLabel.textColor = UIColorFromRGB(0x616163); 
    cellToReturn.eventNameLabel.textColor = UIColorFromRGB(0x616163); 
    cellToReturn.numInviteesLabel.textColor = UIColorFromRGB(0x616163); 
    cellToReturn.numVotesLabel.textColor = UIColorFromRGB(0x616163); 

    self.cell = nil; 
} 

NSString *organizerFbId = [[self.huddleList objectAtIndex:indexPath.row]objectForKey:@"userId"]; 
[cellToReturn.polaroidImageView setImageWithURL:[self.organizerImageUrls objectForKey:organizerFbId] placeholderImage:self.placeholderImage]; 

[[cellToReturn.imageScrollViewHolder subviews] makeObjectsPerformSelector:@selector(removeFromSuperview)]; 
if ([self.avatarScrollViews objectForKey:[[self.huddleList objectAtIndex:indexPath.row]objectForKey:@"id"]]) { 
    [cellToReturn.imageScrollViewHolder addSubview:[self.avatarScrollViews objectForKey:[[self.huddleList objectAtIndex:indexPath.row]objectForKey:@"id"]]]; 
} else { 
    UIScrollView *tempImageScrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 200, 46)]; 
    tempImageScrollView.autoresizingMask = UIViewAutoresizingFlexibleWidth; 
    NSArray *fbUids = [[self.huddleList objectAtIndex:indexPath.row] objectForKey:@"facebookInvitees"]; 
    int i=0; 
    for (i=0;i < [fbUids count];i++) { 
     UIView *polaroidView = [[[UIView alloc] initWithFrame:CGRectMake((i * 45) + (3 * i), 0, 37, 39)] autorelease]; 
     polaroidView.layer.shadowColor = [UIColor blackColor].CGColor; 
     polaroidView.layer.shadowOpacity = 0.3; 
     polaroidView.layer.shadowRadius = 1; 
     polaroidView.layer.shadowOffset = CGSizeMake(5.0f, 5.0f); 

     polaroidView.backgroundColor = [UIColor whiteColor]; 
     UIImageView *img = [[[UIImageView alloc] initWithFrame:CGRectMake(4, 4, 29, 29)] autorelease]; 
     [img setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://graph.facebook.com/%@/picture", [fbUids objectAtIndex:i]]] placeholderImage:self.placeholderImage]; 
     [polaroidView addSubview:img]; 
     [tempImageScrollView addSubview:polaroidView]; 
    } 
    [tempImageScrollView setContentSize:CGSizeMake((i*45) + (3 * i), 46)]; 
    [self.avatarScrollViews setObject:tempImageScrollView forKey:[[self.huddleList objectAtIndex:indexPath.row]objectForKey:@"id"]]; 
    [cellToReturn.imageScrollViewHolder addSubview:tempImageScrollView]; 
    [tempImageScrollView release]; 
} 

return cellToReturn; 
} 
+3

메모리 경고에 cachedScrollViews를 해제하는 것을 잊지 마세요 더 많은 디자인 문제가 여기에 있습니다. 휴대 기기는 많은 스크롤보기를 처리 할만큼 강력하지 않습니다. 또한 한 번에 너무 많은 뷰를 스크롤 할 필요가 없습니다. 디자인을 수정하고 스크롤 할 필요가있을 때만 스크롤보기를 만드시겠습니까? –

+0

좋은 지적이지만, 나에게 제공되는 디자인을 구현하려고하고있다. 내가 할 수있는 게 없니? –

+1

효율성을 향상시키는 방법에 대해 디자이너와상의하십시오. 예를 들어 각 셀에 미리보기를 표시하고 사용자가 행을 선택할 때 전체 이미지 세트 만 표시 할 수 있습니다. – borrrden

답변

0

각 셀의 스크롤러에 고정 된 수의 이미지가 있더라도 셀을 대기열에서 제외하고 다시 사용할 때 할당 할 수 없습니다. 속도를 높이는 방법은 셀 외부의 배열을 테이블 외부에 유지하여 공간을 더 차지하는 것입니다.

huddleList 배열과 동일한 개수의 다른 배열을 만듭니다. 해당 배열을 imageViews가 포함 된 UIScrollViews로 채 웁니다. 당신의 cellForRowAtIndexPath 방법의 모든 것을 코드는 새로운 배열의 초기화 방법으로 이동할 수 있으며, 몇 가지 간단한 선으로 대체 얻을 :

// dequeue or build a cell 

// tag the scroll views so you can find them 
UIScrollView *oldScrollView = (UIScrollView *)[cell viewWithTag:kCELL_SCROLL_VIEW]; 

// this might be a reused cell, so remove the scroll view if it has one 
if (oldScrollView) [oldScrollView removeFromSuperview]; 

// now add the one that you setup for this cell 
// your init code that used to be in this method sets up the frame, the tag, etc 
UIScrollView *currentScrollView = [self.cachedScrollViews objectAtIndex:indexPath.row]; 
[cell addSubview:currentScrollView]; 

// that's it 

나는 그것이 생각

+0

배열 "avatarScrollViews"로 이미이 작업을 수행하고 있지 않습니까? –

+0

수 (코드보다 일반적인 문제에 대한 자세한 답변). 당신이 그 방법으로 할당 한 것을 찾으십시오. 세포 그 자체 외에 각 세포는 속도를 높일 수있는 기회입니다. – danh

+0

어디에서 scrollviews의 할당을 이동시킬 것을 제안 하시겠습니까? 메모리를 염두에두고 테이블을 그리기 전에 모든 가능한 행에 대한 스크롤 뷰를 생성하고 싶지는 않습니다. –

관련 문제