[英]cellForRowAtIndexPath not being called required number of times
我想要實現的功能是,首先我在UITableView
顯示兩行,顯示完美。 然后在didSelectRowAtIndexpath:
,我在UITableView
添加了numberOfRows
,我在添加numberOfRows
和所需數據后重新加載UITableView
。
我的問題是我在numberOfRowsInSection:
傳遞了新的行數numberOfRowsInSection:
我已經檢查過,它正確傳遞)但是在此之后只調用了兩次cellForRowAtIndexpath:
這是之前的numberOfRows
值。
我的代碼:
- (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];
}
可能是什么原因?
任何幫助,將不勝感激!!!
我找到了解決方案。
當我調整我UITableView
按照其數行cellForRowAtIndexPath:
這就是為什么的下一個部分UITableView
是不可見的,並為部分UITableView
這是不可見的, cellForRowAtIndexPath:
不會被調用。
對不起打擾你們。
非常感謝你的幫助!!!
cellForRowAtIndexPath:僅在繪圖時需要立即調用。 您必須構建該方法,而不必控制何時調用它。
嘗試在viewWillAppear
重新加載表
- (void)viewWillAppear:(BOOL)animated {
[tableview reloadData];
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.