如何在 iPhone 中动态设置 Cell 高度?

发布于 2024-10-10 19:48:38 字数 1184 浏览 3 评论 0原文

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

//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 方法。因为我已经设置了单元格框架大小和高度取决于图像高度。那么我如何根据图像高度设置单元格高度?请指导我。

谢谢!

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 - 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
 }

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.

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

聊慰 2024-10-17 19:48:38

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文