2012-05-16 57 views
1

我正在根据您在Interface Builder中设置自定义单元格的值动态设置我的单元格高度。这没有发挥出来,所以我不停地向前,发现苹果的文档这种方法可用于设置单元格的高度 - 的tableView:heightForRowAtIndexPath:为自定义单元格设置uitableviewcell高度

但是我不知道如果我正确地使用它作为无我的tableviewcells正在调整他们的高度,他们都保持相同的标准尺寸。这是我在这里使用的代码。

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    static NSString *CellIdentifier = @"Cell"; 
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 

    // Set cell height 
    [self tableView:tableView heightForRowAtIndexPath:indexPath]; 

    // Configure the cell using custom cell 
    [[NSBundle mainBundle] loadNibNamed:@"CustomcellA" owner:self options:nil]; 
    cell = customcellA; // customcellA getters and setters are set up in .h 

    return cell; 
} 

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    return 44; 
} 

任何帮助,将不胜感激

+0

为什么downvote? – GeneralMike

回答

7

可以说,第三个单元格的两倍,高度:

- (CGFloat) tableView:(UITableView *)tableView 
heightForRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    if(indexPath.row == 2) 
     return 88; 
    return 44; 
} 

这种方法将通过的tableView被调用。

你不应该这样做:

[self tableView:tableView heightForRowAtIndexPath:indexPath]; 

这是你的,你怎么保证,那右边的单元格的indexPath被确定为其它尺寸。

一般规则:
如果您实现一个委托协议的方法,你将永远不会自己调用它。只有具有符合协议的委托的类的对象才会调用委托方法。

+0

你救了我 - 这个答案值得更多的爱 –

0

heightForRowAtIndexPath将自动被调用,你需要返回,你需要自定义的高度。因此,而不是返回44,您需要根据您的数据或任何基于您的身高的高度返回动态高度。

相关问题