2014-11-06 3 views
0

TableView가 깜박 거리는 문제에 관여했습니다. loadmore에 의해 tableview에 데이터를 추가 할 때 TableView가 깜박입니다. 이 코드를 사용하면 모든 것이 잘됩니다.IOS에 추가 된 데이터에 TableView가 추가로 깜박임

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
return 400; 
} 

그러나 각 행의 높이를 계산하고 있습니다. 각 행 높이가 같지 않기 때문입니다. 그런 다음 해당 코드를 적용한 후 My TableView가 깜박입니다.

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSMutableArray *temp; 

if(_buddyWallSection) 
    temp = arrayBuddyList; 
else 
    temp = arrayMyWallList; 

CGFloat height = 320; 
if([[temp objectAtIndex:indexPath.row/2] isKindOfClass:[NSString class]]) 
{ 
    return height; 
} 
CGSize maximumLabelSize = CGSizeMake(280,9999); 
GolferWall *wallComnt = [temp objectAtIndex:indexPath.row/2]; 
CGSize expectedSize = [[self plainTextFromHTMLText:wallComnt.contentTextHTML]sizeWithFont:[UIFont fontWithName:FontNameArial size:15] constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping]; 
height = expectedSize.height; 

NSLog(@"expected size %f", height); 

if(wallComnt.imageNames.count == 0) 
    return 130 + (height); 

if (height < 100) 
{ 
    height = 350; 
} 
else 
    height = height * 2 ; 

return height; 
} 

내가 누락 된 부분을 확인해 주시겠습니까?

여기서 문제는 당신이 CPU를 많이 작업을 행이 표시 되려고 할 때마다 수행하는 것을 당신

+0

, 그 방법은 당신의 jQuery과의 모든 행에 대해 호출을 당신은 CPU 집약적 인 작업 위스콘신 수행 th : ​​ CGSize expectedSize = [[self plainTextFromHTMLText : wallComnt.contentTextHTML] sizeWithFont : [UIFont fontWithName : FontNameArial size : 15] constrainedToSize : maximumLabelSize lineBreakMode : NSLineBreakByWordWrapping]; 제 조언은 모든 행의 크기를 미리 평가하고 테이블 뷰에서 액세스 할 수있는 객체에 해당 정보를 저장하는 것입니다. heightForRowAtIndexPath : – Lolloz89

+0

willDisplayCell 메소드를 구현 한 적이 있습니까? – ZeMoon

+0

@ Lolloz89 예, 시간이 걸립니다. 그것을 고칠 다른 방법이 있습니까? –

답변

0

감사드립니다. 보다 정확하게 문제는 다음 줄에 있습니다.

CGSize expectedSize = [[self plainTextFromHTMLText:wallComnt.contentTextHTML]sizeWithFont:[UIFont fontWithName:FontNameArial size:15] 
constrainedToSize:maximumLabelSize 
lineBreakMode:NSLineBreakByWordWrapping]; 

해결 방법은 모든 개체에 대해 한 번 크기를 미리 평가하는 것입니다.

@property (nonatonic, assign, readonly) CGFloat contentSize; 

을 그리고 GolferWall 초기화 방법에 당신은 단순히 당신이 이미있는 tableView에 쓴 코드를 복사 할 수 있습니다 : 당신의 GolferWall 클래스의 예를 들어, 당신은 다음과 같은 속성을 추가 할 수 있습니다에서 그런

- (instancetype) init 
{ 
    self = [super init]; 
    *** your init stuff here *** 
    self.contentSize = [[self plainTextFromHTMLText:self.contentTextHTML]sizeWithFont:[UIFont fontWithName:FontNameArial size:15] constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping]; 

    return self; 
} 

: heightForRowAtIndexPath를 있는 tableView : heightForRowAtIndexPath : 단순히이 코드 교체 : 당신이 볼 수 있듯이

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
NSMutableArray *temp; 

if(_buddyWallSection) 
temp = arrayBuddyList; 
else 
    temp = arrayMyWallList; 

CGFloat height = 320; 
if([[temp objectAtIndex:indexPath.row/2] isKindOfClass:[NSString class]]) 
{ 
    return height; 
} 
CGSize maximumLabelSize = CGSizeMake(280,9999); 
GolferWall *wallComnt = [temp objectAtIndex:indexPath.row/2]; 

// The magic is here 
CGSize expectedSize = wallComnt.contentSize; 
height = expectedSize.height; 

NSLog(@"expected size %f", height); 

if(wallComnt.imageNames.count == 0) 
    return 130 + (height); 

if (height < 100) 
{ 
    height = 350; 
} 
else 
    height = height * 2 ; 

return height; 
} 
관련 문제