2013-04-29 116 views
0

我有CustomCellView这是tableview中单元格的自定义视图。我在xib中有UIButton,并将其设置为xib中的默认框架。UITableViewCell UIButton动态高度

MainViewControllerviewDidLoad

// Get nib for custom cell 
UINib *nib = [UINib nibWithNibName:@"CustomFeedCell" bundle:nil]; 
[self.mainTableView registerNib:nib forCellReuseIdentifier:@"CustomFeedCell"]; 

在cellForRow ...

CustomFeedCell *cell = [self.mainTableView dequeueReusableCellWithIdentifier:@"CustomFeedCell"]; 

// here i need to set UIButton frame (height) depending on image height. 
// I have tried diferent ways and it always return height set in CustomCellView xib 

回答

0

如果你想创建按钮,图像等在UIView动态,你必须使用viewDidLoad:方法和不使用xibs。

0

好吧,所以我从你的问题理解是你有问题设置您的tableview单元格中存在的按钮的动态高度。它有时可能不止是细胞的高度,有时甚至可能比细胞的高度更低。你想相应地调整它。正确吗?

如果那是你的问题,那么你可以在委托 的tableView设置你的每一个细胞的tableview高度:heightForRowAtIndexPath:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return [indexPath row] * 20; // your desired height 
} 

希望这能解决你的问题。

相关问题