我正在尝试使用以下代码动态调整UITableView单元格的高度。目前,仅return 200;被调用。

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *description = [photosFromCommentsArray objectAtIndex:indexPath.row];

    NSLog(@"description is %@",description);

    if(description == NULL)
        return 60;

    else {
        return 200;
        }
}


描述的NSLog输出是:

如您所见,有时在这种情况下我想返回return 60;,并且当它包含除我想返回的return 200;以外的其他内容时

2013-09-12 16:30:36.567 1000 [11619:907] description is <null>
2013-09-12 16:30:36.568 1000 [11619:907] description is <null>
2013-09-12 16:30:36.569 1000 [11619:907] description is <null>
2013-09-12 16:30:36.569 1000 [11619:907] description is <null>
2013-09-12 16:30:36.570 1000 [11619:907] description is (
    "http://****.net/uploads/nodes/1464/photos/a0d41e7834b5119884c6fa83aaffb3023f609c0e.jpeg"
)
2013-09-12 16:30:36.571 1000 [11619:907] description is (
    "http://****.net/uploads/nodes/1464/photos/739701d7609bcb65ce5293f3551773c6bb6a498d.jpeg"
)
2013-09-12 16:30:36.572 1000 [11619:907] description is (
    "http://****.net/uploads/nodes/1464/photos/99cf9e662b0d4f00e316bd2f8c01faddb20e9473.jpeg"
)
2013-09-12 16:30:36.572 1000 [11619:907] description is (
    "http://*****.net/uploads/nodes/1464/photos/a6680113da9567b8477810703e14616631c39a06.jpeg"
)

最佳答案

您没有显示photosFromCommentsArray的初始化方式。因此,请尝试以下操作:

if(description == (id)[NSNull null])
    return 60;
else
    return 200;


要么:

if(description == nil)
    return 60;
else
    return 200;

10-05 21:00
查看更多