heightForRowAtIndexPath仅用于一节? [英] heightForRowAtIndexPath for only one section?

查看:55
本文介绍了heightForRowAtIndexPath仅用于一节?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我现在面临的问题:

This is the problem I'm facing right now:

我有很多UITableViews,每个UITableViews有两个部分(根据需要随时显示一个).第一部分有3个单元格,可能需要调整其大小.因此,我正在使用heightForRowAtIndexPath.

I've got a lot of UITableViews with two sections each (only one is displayed at any time, on demand). The first section has got 3 cells, which might need to be resized. Because of that, I'm using heightForRowAtIndexPath.

第二部分最多可以包含3.000个单元格,全部使用默认高度44点.

The second section might have up to 3.000 cells, all using the default height of 44 points.

我的heightForRowAtIndexPath确定是要处理第1节还是第2节中的单元格,然后进行测量(第1节)还是立即返回默认值(第2节44).

My heightForRowAtIndexPath determines whether it is treating a cell from section 1 or from section 2 and then either measures (section 1) or immediately returns the default value (44 section 2).

通过这种方法,大表视图需要花费一些时间才能显示出来,因为在这种情况下(大约1.000个单元格以上),heightForRowAtIndexPath是一个性能问题.

By using this method, large table views take a little while to be displayed, since heightForRowAtIndexPath is a performance issue in cases like this (more than about 1.000 cells).

我的问题是:有什么方法可以仅调整第一部分中介绍的3个单元格的大小?有什么办法可以强制只为indexPath.section == 0调用heightForRowAtIndexPath吗?

My question is: Is there any way to resize just the 3 cells presented in the first section? Any way to maybe force heightForRowAtIndexPath to be called just for indexPath.section == 0?

如果有什么不同,我使用的是分组表格视图.

In case it makes any difference, I'm using a grouped table view.

谢谢.

推荐答案

heightForRowAtIndexPath .如果您只想更改第一部分中的值,则只需使用简单的 if 语句.可能看起来像:

heightForRowAtIndexPath is going to be called if it is implemented in your delegate. If you're only looking to change the values in the first section, then just use a simple if statement. This could look like:

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    // Test to see what section you're in
    if ([indexPath section] == 0) {
        // return the height for the first section
    } else {
        // return the height for everything other than the first section
    }
}

干杯.

这篇关于heightForRowAtIndexPath仅用于一节?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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