2015-10-20 114 views
0

好吧我很确定这种方法一直执行到现在为止我的UITableViewController。我有打印语句在我的方法,像这样:heightForRowAtIndexPath永远不会被调用iOS9

- (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文件,并正确设置了代表团:在我viewDidLoad:方法

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

。为什么我的heightForRowAtIndexPath根本不被调用?

+0

为什么你还要在函数的开始return语句? – Fonix

+0

Uhm,如果只有条件中没有返回,则方法错误? – Chisx

+1

返回语句立即结束函数,因此它下面的代码将永远不会执行 – Fonix

回答

1

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

1

尝试这样

EDITED

- (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; 
} 
+0

如果这三个条件中的任何一个都不是真的,而是所期望的'475',则这将返回'0'。 – rmaddy

+0

希望这将返回475 :-) – Prakash

+0

现在你只需要将'height'改为'CGFloat'而不是'int'。 – rmaddy

相关问题