0
我有一個表格視圖,它在選擇日期彈窗時自動加載。 我要選擇最後的tableview細胞(目前是不可見的),它應滾動到底將tableView滾動到最後一行的底部選擇
我寫了下面的代碼
- (void)viewDidLoad {
[_tableView reloadData];
[self scrollTableToIndex];
[_tableView selectRowAtIndexPath:[NSIndexPath indexPathForRow:_selectedMeetingIndex inSection:0] animated:YES scrollPosition:UITableViewScrollPositionNone];
[self tableView:_tableView didSelectRowAtIndexPath:[NSIndexPath indexPathForRow:_selectedMeetingIndex inSection:0]];
}
-(void)scrollTableToIndex{
if(_selectedMeetingIndex <= _arrMeetingsList.count/2){
_isTableBottomScrolled = NO;
[_tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:_selectedMeetingIndex inSection:0] atScrollPosition:UITableViewScrollPositionTop animated:YES];
}else{
NSLog(@"_tableView.contentOffset.y %f",_tableView.contentOffset.y);
if (!_isTableBottomScrolled) {
_isTableBottomScrolled = YES;
CGFloat height = self.agendaList.contentSize.height - self.tableView.bounds.size.height;
[self.tableView setContentOffset:CGPointMake(0, height) animated:YES];
}
}
}
的實現代碼如下細胞被選擇,但它不第一次滾動到底部,但是如果我從日期彈出窗口中選擇不同的日期,它會滾動到底部並選擇單元格。
我也在viewDidAppear
中調用了函數「scrollTableToIndex
」,但它不起作用。
另外,如果我用這個
[self.tableView setContentOffset:CGPointMake(0, CGFLOATMAX) animated:YES];
,而不是下面的代碼行
CGFloat height = self.agendaList.contentSize.height - self.tableView.bounds.size.height;
[self.tableView setContentOffset:CGPointZero animated:YES];
如果我這樣做,那麼該代碼適用於第一次的時間,但第二次,之後我選擇日期從popover,桌面視圖掛起。
我已經提到這個link
請幫助。