2012-03-20 45 views

回答

1

通過委託方法傳遞按鈕按下事件視圖控制器和重載表視圖如下。

[self.tableView reloadData];

鑑於控制器(即,數據源爲表視圖),實施heightForRowAtIndexPath方法,並根據需要返回的高度。

1

您可以在委託方法

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{ 
if(indexPath.row == clickedRow) 
    return newHeitht; 

return cellHeight; 
} 

可以設置在點擊按鈕的一些條件,並重新加載使用[tableView reloadData]的實現代碼如下更改單元格高度。這個函數將被調用。爲特定單元格返回一個新的高度。

0
[self.tableView beginUpdates]; 
[self.tableView reloadRowsAtIndexPaths:toReloadRows withRowAnimation: UITableViewRowAnimationNone]; 
[self.tableView endUpdates]; 

然後

[self.tableView beginUpdates]; 
[self.tableView endUpdates]; 
0
-(void)buttonClick { 

[self.tableview reloadData]; 

selectedRow = //do something here 

} 

,並在您的UITableView數據源

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

if(indexPath.row == selectedRow) 

return selectedRowHeight; 
else 
return defaultHeight; 

} 
0
(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {  

    if (isSearching && indexPath.row == selectedIndex) { 
     return 110; 
    } 
    else { 
     return rowHeight;  
    } 
0

1)創建一個自定義的UITableViewCell類。 2)填充你的細胞,但你認爲合適。我自己使用'hydrateWithArray'類型的函數。 3)數據填充後,使用'sizeToFit'函數調整大小和重新定位元素,以強制標籤符合您放入其中的任何尺寸。 protip:通過首先設置標籤的框架,並將行的數量設置爲0 ...當您填充文本和sizetofit時,它只會垂直拉伸標籤並強制寬度保持不變。 4)創建一個單獨的函數(我的稱爲calculatedHeight),它返回一個浮點數並返回希望單元格在表格中的高度(基於步驟3中重新定位的對象)。

- (float)calculatedHeight { 
return textLabel.frame.origin.ytextLabel.frame.size.height5; 
} 

5)在你的UITableView類,你需要導入tableViewCell類,並創建一個虛擬單元對象。你將使用這個類來計算每個單元格的高度。然後在heightOfRowAtIndex方法....

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
float height; 
if (!dummyCell) dummyCell = [[CustomCell alloc] initWithFrame:CGRectMake(0,0,0,0) reuseIdentifier:@"myCell"]; 
[dummyCell hydrateWithTweet:[tableArray objectAtIndex:indexPath.row]]; 
height = [dummyCell calculatedHeight]; 
if (height == 0) height = 50; 
return height; 
} 

這是一個非常簡單的例子,所以你可能需要去瘋狂在您的特定使用錯誤檢查,但是這至少應該點你在正確的方向。請享用!

相關問題