UITableView ->numberOfRowsInSection:(NSInteger)section 返回错误的值 [英] UITableView -> numberOfRowsInSection:(NSInteger)section returns wrong value

查看:27
本文介绍了UITableView ->numberOfRowsInSection:(NSInteger)section 返回错误的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我今天第二次...但是这里有很多优秀的开发人员...

我的 tableView 有一些问题...如果视图出现,我的表格会重新加载其数据,但它不会更新 numbersOfRowsInSection...

I have some troubles with my tableView... If the view will appear my table reloads its data, but it doesn't update the numbersOfRowsInSection...

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    NSLog(@"COUNTER: %i",[content count]);
    return [content count];
}

日志显示我第一次加载页面时的值是正确的.但是如果我添加一个对象并重新加载数据,这个函数就不会调用.

The log says the first time I load the page the right value. But if I add an object and reload the data, this function isn't calling.

有人知道解决办法吗?

谢谢,mavrick3.

Thanks, mavrick3.

这是我如何调用 [table reloadData]

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if ([content count] != 0) {
        self.content = [[[[NSArray alloc] initWithContentsOfFile:[FileManager filePath]] objectAtIndex:row_] objectForKey:@"faecher"];
        [table reloadData];
        NSLog(@"----%@",content);
    }
}

是的,数据源和委托是连接的,它们都在我的标题中实现.

And yes, the dataSource and delegate are connected and they are both implemented in my header.

推荐答案

如果你在 UITableview 对象上调用 reloadData 并且你是它的 dataSource 那么这个方法应该被调用.

If you call reloadData on a UITableview object and you're it's dataSource then this method should be called called.

您确定已将表格视图分配给您的属性(即在界面构建器中将其拖过?)

Are you sure that you have assigned your table view to your property (i.e. dragged it across in interface builder?)

我怀疑你只是让你的控制器成为你的表视图的数据源(因此它第一次加载它时获取值).之后,您对 reloadData 的调用将不起作用,因为您的视图控制器中的属性仍然为零.

I suspect that you have only made your controller the dataSource of your table view (hence the first time it loads it gets the value). After that your calls to reloadData won't work because the property in your view controller is still nil.

您可以通过在调用 reloadData 之前放置一个 NSLog 来测试这一点 - 如果它输出 nil,那么您还没有连接它.

You can test this by putting an NSLog just before you call reloadData - if it outputs nil then you've not connected it.

NSLog(@"%@", myTable);
[myTable reloadData];

这篇关于UITableView ->numberOfRowsInSection:(NSInteger)section 返回错误的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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