简体   繁体   English

UITableView委托方法

[英]UITableView Delegate Method

I'm trying to adjust the height of only the last row of a table view. 我正在尝试仅调整表格视图最后一行的高度。 I seem to be encountering some sort of recursive loop when trying to find the index of the last row. 尝试查找最后一行的索引时,似乎遇到了某种递归循环。 In my heightForRowAtIndexPath: method I have the following: 在我的heightForRowAtIndexPath:方法中,我具有以下内容:

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
CGFloat height = 60;

    NSInteger lastSectionIndex = [tableView numberOfSections] - 1;
    NSInteger lastRowIndex = [tableView numberOfRowsInSection:lastSectionIndex] - 1;  // BLOWS UP!

    if ((indexPath.section == lastSectionIndex) && (indexPath.row == lastRowIndex)) {
        height = 44;
    }

    return height;
}

If I tweak the code a just a little, it works. 如果我稍微调整一下代码,它就可以工作。

NSInteger lastRowIndex = [self tableView:tableView numberOfRowsInSection:lastSectionIndex] - 1;  // WORKS!

Can any Objective-C/iOS gurus shine some light as to what's going on here? 任何Objective-C / iOS专家都可以对这里发生的事情有所了解吗? Why does one syntax work over the other? 为什么一种语法优于另一种语法? Aren't they the exact same method? 他们不是完全一样的方法吗?

You can check out the code here for context: https://github.com/phungkytown/chapter8_gold 您可以在此处查看上下文代码: https : //github.com/phungkytown/chapter8_gold

Any help is greatly appreciated! 任何帮助是极大的赞赏!

我建议不要使用tableView委托来获取节数和行数,而应直接从数据源获取此信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM