iOS UITableView numberOfRowsInSection在tableView heightForRowAtIndexPath中给予不良访问 [英] iOS UITableView numberOfRowsInSection in tableView heightForRowAtIndexPath give BAD ACCESS

查看:190
本文介绍了iOS UITableView numberOfRowsInSection在tableView heightForRowAtIndexPath中给予不良访问的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在[tableView numberOfRowsInSection:0]下输入if语句时收到EXC错误访问错误.我正在计算heightForRowAtIndexPath内的UITableView的tableView numberOfRowsInSection.

I have receive a EXC Bad Access error when I enter the if statement below [tableView numberOfRowsInSection:0].I'm calculating the tableView numberOfRowsInSection of the UITableView inside the heightForRowAtIndexPath .

我有以下代码来设置第一部分最后一行的高度

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

        if (indexPath.section==0) {
            NSInteger lastRowIndex = [tableView numberOfRowsInSection:0] - 1;

            if (indexPath.row==lastRowIndex) {
                return 44.0f;

            }else{
                return 100;

            }

        }else{

            return 100;
        }


}

我收到如下图所示的错误

我认为此方法不合适

iOS UITableView numberOfRowsInSection错误访问权限

- (int) myNumberOfRowsMethod{
    // Here you would usually have some underlying model 
    return [self.myContactsOrWhateverArray count];
}

推荐答案

尝试此方法 [self tableView:tableView numberOfRowsInSection:0]而不是[tableView numberOfRowsInSection:0].很好.

Try this method [self tableView:tableView numberOfRowsInSection:0] instead of [tableView numberOfRowsInSection:0]. It's works fine.

这篇关于iOS UITableView numberOfRowsInSection在tableView heightForRowAtIndexPath中给予不良访问的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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