[英]cellForRowAtIndexPath not being called required number of times
The functionality that I am trying to achieve is that first I am showing two rows in a UITableView
which is showing perfectly. 我想要实现的功能是,首先我在
UITableView
显示两行,显示完美。 Then on didSelectRowAtIndexpath:
, I am adding the numberOfRows
in the UITableView
, for which I am reloading the UITableView
after adding the numberOfRows
and the required data. 然后在
didSelectRowAtIndexpath:
,我在UITableView
添加了numberOfRows
,我在添加numberOfRows
和所需数据后重新加载UITableView
。
My problem is that I am passing the new number of rows in the numberOfRowsInSection:
(which I have checked, it is passing correctly) but cellForRowAtIndexpath:
is called only two times after that, which is the previous numberOfRows
value. 我的问题是我在
numberOfRowsInSection:
传递了新的行数numberOfRowsInSection:
我已经检查过,它正确传递)但是在此之后只调用了两次cellForRowAtIndexpath:
这是之前的numberOfRows
值。
My Code: 我的代码:
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return self.currentSubCategoryRows;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
// My code for cell construction goes here
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
[self.arrWithAdditionalValues addObjectsFromArray:[self.dictSubCategoriesLevel3 objectForKey:[NSString stringWithFormat:@"%d",rowOpened]]];
self.currentSubCategoryRows += self.arrWithAdditionalValues.count;
[tableView reloadData];
}
What could be the reason? 可能是什么原因?
Any help would be appreciated!!! 任何帮助,将不胜感激!!!
I found the solution. 我找到了解决方案。
As I was resizing my UITableView
as per its number of rows in cellForRowAtIndexPath:
, that's why the next part of the UITableView
was not visible, and for the part of the UITableView
which is not visible, cellForRowAtIndexPath:
is never called. 当我调整我
UITableView
按照其数行cellForRowAtIndexPath:
这就是为什么的下一个部分UITableView
是不可见的,并为部分UITableView
这是不可见的, cellForRowAtIndexPath:
不会被调用。
Sorry to bother you all. 对不起打扰你们。
Thanks a lot for your help!!! 非常感谢你的帮助!!!
cellForRowAtIndexPath: is only called as soon as is needed for drawing. cellForRowAtIndexPath:仅在绘图时需要立即调用。 You have to build that method without controlling when it will be invoked.
您必须构建该方法,而不必控制何时调用它。
Try to Reload table in viewWillAppear
尝试在
viewWillAppear
重新加载表
- (void)viewWillAppear:(BOOL)animated {
[tableview reloadData];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.