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

    TRSocialCell *cell = (TRSocialCell *)[self.tableView dequeueReusableCellWithIdentifier:@"cell"]; 
    if (cell == nil) { 
     NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"TRSocialCell" owner:self options:nil]; 
     cell = [nib objectAtIndex:0]; 

     __weak TREvent *eventFromParse; 
     if (!isSearchingEvents){ 
      if ([filteredArray[indexPath.section] count] == 0) { 
       [cell displayForNoEvents]; 
       cell.selectedBackgroundView = bgCell; 
       return cell; 
      } else { 
       eventFromParse = filteredArray[indexPath.section][indexPath.row]; 
      } 
     } 
     else eventFromParse = searched[indexPath.row]; 

     //Cover Image 
     [eventFromParse.fileForCover getDataInBackgroundWithBlock:^(NSData *data, NSError *error) { 
      if (!error) { 
       eventFromParse.coverPicture = [UIImage imageWithData:data]; 
       cell.coverView.image = [UIImage imageWithData:data]; 

      } else { 
       [TRAppDelegate displayInternetErrorForView:self.view]; 
      } 

     }]; 

     cell.titleAutoLabel.text = [NSString stringWithFormat:@"%@",eventFromParse.title]; 
     cell.titleAutoLabel.fadeLength = 0; 
     cell.titleAutoLabel.pauseInterval = 2.0f; 
     [animatedLabels addObject:cell.titleAutoLabel]; 

     if (eventFromParse.location != nil) { 
      cell.addressLabel.text = [NSString stringWithFormat:@"%@",eventFromParse.location.name]; 
     } 

     [cell.titleAutoLabel setFont:[UIFont fontWithName:@"BigNoodleTitling" size:26]]; 
     [cell.titleAutoLabel setTextColor:[UIColor whiteColor]]; 
     [cell.addressLabel setFont:[UIFont fontWithName:@"BigNoodleTitling" size:18]]; 
     [cell.addressLabel setTextColor:[UIColor whiteColor]]; 
     [cell.dateLabel setFont:[UIFont fontWithName:@"BigNoodleTitling" size:18]]; 
     [cell.dateLabel setTextColor:[UIColor whiteColor]]; 

     cell.dateLabel.text = [NSString stringWithFormat:@"%@ - %@",[TRAppDelegate convertDateToDate:eventFromParse.date],[TRAppDelegate convertDateToTime:eventFromParse.date]]; 
     cell.selectedBackgroundView = bgCell; 
    } 

    return cell; 
} 

메모리가 커지고 있지만 찾을 수없는 문제가 있습니다. 정상적인 경우 if (! 셀) {} 다른 셀로 스크롤 할 때마다 호출됩니다.cellForRowAtIndexPath에서 증가하는 라이브 바이트 수 :

뷰 컨트롤러의 dealloc에서 nil 속성을 설정해야합니까?

이 코드는 어느 정도 유출 될 수 있습니까?

+2

짧은 대답 : 아니요, 처음 몇 개의 셀만 화면에 표시해야하며 기존 셀을 다시 사용해야합니다. 그건 그렇고, 여기에 셀에 데이터를 설정하기위한 올바른 패턴이있다. (옛 방식을 사용하고있다. 새로운 방법은'if (cell == nil) '체크를 사용하지 않는 프로토 타입 셀을 사용한다.) https : //gist.github.com/iwasrobbed/1656ddf1b0ca645bd123 – iwasrobbed

답변

1

메모리가 증가하지만 문제가 발생했는데 찾을 수 없습니다. 정상적인 경우 if (! 셀) {} 다른 셀로 스크롤 할 때마다 호출됩니다.

아니. 새로 할당 된 셀을 재사용 큐에 넣지 않았습니다. 따라서 새로운 셀을 제공해야 할 때마다 기본적으로 새로운 펜촉을 RAM에로드합니다. 당신이 그것을하는 방법, 새로운 TRSocialCell 그들의 재사용 식별자가 뭔지 전혀 몰라 - 그리고 그러므로 그들은 분명히 전혀 재사용하지 않습니다.

당신의 TRSocialCell 구현 파일 안에 다음과 같은 방법을 구현하려고, 그래서 당신의 세포는 반환 할 수 있습니다 자신의 reuseIdentifier 시스템에 의해 요구되는 경우 :
'셀'영리한 선택이되지 않습니다 : 그런데

- (NSString *)reuseIdentifier { 
    return @"cell"; 
} 

reuseIdentifier입니다. 다른 유형의 셀을 언젠가 사용하고 싶다면 재사용 대기열을 망칠 수 있습니다. 식별자에 클래스 이름을 포함하는 것이 좋습니다. 예를 들어 TRSocialCellID

+0

고마워! 재사용 식별자를 변경하고 프로토 타입 셀을 삭제했습니다! 그리고 BAM! 그것은 효과가 있었다. 다시 한번 감사드립니다. –

관련 문제