RowAtIndexPath的高度从未被称为iOS9
好的,我很确定这个方法一直在我的RowAtIndexPath的高度从未被称为iOS9,ios,uitableview,heightforrowatindexpath,Ios,Uitableview,Heightforrowatindexpath,好的,我很确定这个方法一直在我的UITableViewController中执行。我的方法中有如下打印语句: - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath { //455(PERFECT MIN HEIGHT) 475 is perfect spacing. 15.5 is the scalar for when descriptionLabel
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;
在my
viewDidLoad:
方法中。为什么我的heightForRowAtIndexPath
根本没有被调用?您只需要将函数顶部的return语句移到底部,或者将其作为当前if语句的一部分放在else中,因为return语句会立即结束函数,因此它下面的代码永远不会执行。尝试这样做
已编辑
- (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;
}
为什么在函数的开头有一个return语句?嗯,如果只在条件中,方法会因为没有返回而出错?return语句会立即结束函数,因此下面的代码永远不会执行。你是对的。。好的,我会改变它,如果我需要一个开放式的非条件返回语句在条件之后,我如何防止它返回475?你可以,但这与将return语句移到函数末尾是一样的,如果这三个条件都不是真的,那么您的选择将返回
0
,而不是所需的475
。希望这将返回475:-)现在您只需要将height
更改为CGFloat
,而不是int
。