0
我參與了TableView閃爍問題。當我通過loadmore在tableview中追加數據時,TableView閃爍。如果我使用這個代碼,那麼一切都很好。TableView閃爍在更多的數據追加在IOS
-(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;
}
可能請您檢查我缺少的東西嗎?
謝謝
正如你所看到的,調用該方法在你的UITableView每一行和要執行的CPU密集型任務的Wi我們可以通過下面的例子來說明CGSize expectedSize = [[self plainTextFromHTMLText:wallComnt.contentTextHTML] sizeWithFont:[UIFont fontWithName:FontNameArial size:15] constrainedToSize:maximumLabelSize lineBreakMode:NSLineBreakByWordWrapping]; 所以我的建議是預先評估每行的大小並將該信息存儲在可從tableview訪問的對象中:heightForRowAtIndexPath: – Lolloz89 2014-11-06 08:42:24
您是否偶然實現了willDisplayCell方法? – ZeMoon 2014-11-06 08:43:48
@ Lolloz89是的,所以它需要時間。我們有另一種解決方法嗎? – 2014-11-06 08:44:47