0

好吧,我很确定这个方法一直执行到现在我的UITableViewController. 我的方法中有打印语句,如下所示:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //455(PERFECT MIN HEIGHT) 475 is perfect spacing. 15.5 is the scalar for when descriptionLabel expands lines
    return 475;
    NSLog(@"ISSSS ITTT ONNNN???");

    if (currentDescriptionHeight == 16.0) {
        NSLog(@"OHHH so it triggered 1111");
        return 475;
    }else if (currentDescriptionHeight == 31.5){
        NSLog(@"OHHH so it triggered 2222");
        return 490.5;
    }else if (currentDescriptionHeight == 47){
        NSLog(@"OHHH so it triggered 3333");
        return 506;
    }

    //475 - 1 line description,
}

我已将方法标头复制到我的.h文件中,并已正确设置委托:

self.tableView.delegate = self;
self.tableView.dataSource = self;

在我的viewDidLoad:方法中。为什么我heightForRowAtIndexPath根本没有被叫到?

4

2 回答 2

1

像这样试试

已编辑

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

CGFloat height = 475;
NSLog(@"ISSSS ITTT ONNNN???");

if (currentDescriptionHeight == 16.0) {
    NSLog(@"OHHH so it triggered 1111");
    height = 475;
}else if (currentDescriptionHeight == 31.5){
    NSLog(@"OHHH so it triggered 2222");
    height = 490.5;
}else if (currentDescriptionHeight == 47){
    NSLog(@"OHHH so it triggered 3333");
    height = 506;
}

return height;
}
于 2015-10-20T03:01:54.260 回答
1

您只需要将函数顶部的 return 语句移到底部,或者将其作为当前 if 语句的一部分放在 else 中,因为 return 语句会立即结束函数,因此它下面的代码将永远不会执行。

于 2015-10-20T02:27:22.950 回答