如何在iPhone中动态设置单元格高度? [英] How to set the Cell height as dynamically in iPhone?

查看:78
本文介绍了如何在iPhone中动态设置单元格高度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In my apps, i have created table view and displayed the images and the labels in the table view. I have downloaded the image and set the image height into the another class and i have passed the image height value using delegates. In my problem is, heightForRowAtIndexPath method is call very earlier and it never calls again. So how i set the cell height depends on the image height?

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

//appDelegate.imageHeight - Image height delegate value.

- (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方法。因为我已经设置了单元格的大小和高度取决于图像的高度。那么如何设置像元高度取决于图像高度?

Is any possible to call the heightforRowAtIndexPath method inside the cellForRowAt method. Because i have set the cell frame size and height depends on the image height. So how can i set the cell height depends on the image height?, please guide me.

谢谢!

推荐答案

heightForRowAtIndexPath方法在cellForRowAtIndexPath之前被调用,因此您需要知道要显示在单元格中的图像的高度。维护包含传递给此类的图像高度的字典或数组,并使用其相应地设置单元格的高度

heightForRowAtIndexPath method is called before cellForRowAtIndexPath, so you need to know height of images you are displaying in your cells. Maintain the dictionary or array that contains height of images which get passed to this class and use it to set the height of cell accordingly

这篇关于如何在iPhone中动态设置单元格高度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆