내 문제는 아주 단순 해 보이지만 여기 또는 다른 해결책을 찾지 못했습니다. 내 UIView 중 하나에 서브 클래스로 UITableView
이 있습니다. 응용 프로그램이 끝나면 마지막으로 선택한 표 셀이 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;
}