2012-06-05 21 views
0

我想要一個單元格,其中rowHeight等於UITableView的高度。 添加我添加新的細胞,然後roWHeight除以我有的細胞總量。我想增加rowHeight,因爲我將新單元格添加到UITableView

在我的viewDidLoad裏我設置了默認的高度。我有:

myCellHeightNum = [[NSNumber alloc] initWithInt:100]; 
//not sure how to get the height of the UITableView so i set it to 100 

在我-(IBAction) AddCell方法我有:

[myTableView beginUpdates]; 
double value = [myCellHeightNum doubleValue]; 
myCellHeightNum = [NSNumber numberWithDouble:value * value/numOfCells]; 
[myTableView reloadData]; 

IDK的,任何想法。

感謝,

+0

什麼是在cellFroRowAtIndexPath編輯的自定義單元格? – geminiCoder

回答

0

寫這個功能

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { 
    double value = [myCellHeightNum doubleValue]; 
    myCellHeightNum = [NSNumber numberWithDouble:value * value/numOfCells]; 
    return [myCellHeightNum floatValue]; 
} 
1

使用這種方法

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
+0

但是請注意,在顯示錶之前,每個單元格都會調用此方法,因此請勿在此執行任何昂貴的計算,否則您的應用程序將顯示爲掛起。 – borrrden

相關問題