我的问题似乎很简单,但我没有找到解决方案在这里或其他地方。 我有一个UITableView
作为我的UIViews中的一个子类。当应用程序完成最后选择的表格单元格被保存到NSUserDefaults
,并且当应用程序重新启动时,我想设置选定的单元格,因为它以前。然而,当我做得太早时会导致问题,因为部分的数目未知,即表尚未加载其数据。所以我决定在函数numberOfRowsInSection
中设置它,但是我相信这不是正确的地方。UITableView何时完成更新?
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section
{
int iNofRows = 0; //Default
// It is not great doing this here but....
if(bSetDefaultSelection == YES)
{
bSetDefaultSelection = NO; // Stop recursion
**NSIndexPath* indexPath = [NSIndexPath indexPathForRow:(NSUInteger)l last_sel_row inSection:(NSUInteger)0];
[self selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];**
}
return iNofRows;
}