這是我想要在我的應用程序。下面顯示的是在iPhone App Store的兩張截圖:UITableView不自然的混亂隨着細胞高度動態變化
基本上,我需要一個「更多」,就像它在App Store中使用功能(見「描述「部分在上面的兩個圖像)。我假設這裏的每個部分(說明,新增功能,信息等)是一個表格視圖單元格。裏面的文本是UILabel或UITextField。
這是我迄今爲止嘗試添加此功能:
NSString *initialText = @"Something which is not a complete text and created just as an example to...";
NSString *finalText = @"Something which is not a complete text and created just as an example to illustrate my problem here with tableviews and cel heights. bla bla bla";
NSInteger isReadMoreTapped = 0;
我的cellForRowAtIndexPath功能:
// Other cell initialisations
if(isReadMoreTapped==0)
cell.label.text = initialText;
else
cell.label.text = finalText;
return cell;
我heightForRowAtIndexPath功能:
// Other cell heights determined dynamically
if(isReadMoreTapped==0){
cell.label.text = initialText;
cellHeight = //Some cell height x which is determined dynamically based on the font, width etc. of the label text
}
else{
cell.label.text = finalText;
cellHeight = //Some height greater than x determined dynamically
}
return cellHeight;
最後我IBAction爲readMoreTapped方法是當更按鈕被竊聽稱爲:
isReadMoreTapped = 1;
[self.tableView beginUpdates];
[self.tableView endUpdates];
NSIndexPath* rowToReload = [NSIndexPath indexPathForRow:2 inSection:0]; // I need to reload only the third row, so not reloading the entire table but only the required one
NSArray* rowsToReload = [NSArray arrayWithObjects:rowToReload, nil];
[self.tableView reloadRowsAtIndexPaths:rowsToReload withRowAnimation:UITableViewRowAnimationNone];
做這一切後,我就得到了所需的功能。計算該特定單元格的新高度,並將新文本加載到該高度。 但是在TableView上有一個非常不自然的混亂,導致不良的用戶體驗。但應用商店更多按鈕雖然不是這種情況。其案件中沒有不自然的混蛋。 TableView保留在它的位置,只有被更改的單元格的大小隨着文本的平滑顯示而增加。
我如何能實現平滑如在iPhone應用程序商店更按鈕來完成?
您是否在重載方法中嘗試了其他行動畫? –
你能描述一下「混蛋」嗎?尺寸是否仍然具有新的價值?在滾動位置,單元格的內容是否是一個混蛋? – jrturton
@ LithuT.V是的,我有。行爲沒有變化 –