2011-01-07 99 views
1

在我的应用程序中,我创建了表格视图并在表格视图中显示了图像和标签。我已经下载了图像并将图像高度设置为另一个类,并且我使用代表传递了图像高度值。在我的问题是,heightForRowAtIndexPath方法调用非常早,它再也不会调用。那么我如何设置单元高度取决于图像高度?如何在iPhone中动态设置单元高度?

//appDelegate.imageHeight - 图像高度委托值。

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

NSLog(the height of the image is --------------------------%f, appDelegate.imageHeight); 
In Console: 
    the height of the image is --------------------------0.000000 
    the height of the image is --------------------------0.000000 
    the height of the image is --------------------------0.000000 
} 

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 
    NSLog(the height of the image is --------------------------%f, appDelegate.imageHeight); 
    In Console: 

     the height of the image is --------------------------98.567039 
     the height of the image is --------------------------300.000000 
     the height of the image is --------------------------232.288406 
} 

是否有可能在cellForRowAt方法内调用heightforRowAtIndexPath方法。因为我已经设置了单元格框架的大小和高度取决于图片的高度。那么如何设置单元格高度取决于图像高度?请引导我。

谢谢!

+1

我试图向应用添加类似的行为;发现这个帖子,这可能有一个解决方案? - 回答说调用[tableView beginUpdates];和[tableView endUpdates]看起来很有希望? :http://stackoverflow.com/questions/460014/can-you-animate-a-height-change-on-a-uitableviewcell-when-selected – petert 2011-01-07 11:59:16

回答

1

heightForRowAtIndexPath方法的cellForRowAtIndexPath之前调用,所以你需要知道你在你的细胞中已显示图片的高度。维护包含图像高度的字典或数组,并将其用于设置单元格高度

+0

感谢您的答复。但图像高度值只能在cellForRowAtIndexPath方法中获得,如果我创建任何字典或数组,那么如何将这些值传递给heightForRowAtIndexPath方法?所以是否有可能在cellForRowAtIndex方法中调用“heightForRowAtIndexPath”或者其他一些解决方案?谢谢。 – Pugal 2011-01-07 12:04:58

相关问题