當我的View(包含Table View)加載時,我希望它滾動到表格視圖的底部。這很好。但是,當我點擊一個按鈕(sendReply)時,我也希望tableView滾動到底部。出於某種原因,當視圖最初加載時,滾動到tableView的底部工作,但是當我將它放在我的sendReply動作中時,[self bottomScroll:self]似乎不會觸發?當點擊uibutton時,以編程方式滾動到tableView底部
.M
-(void)viewDidAppear:(BOOL)animated {
[super viewDidAppear:animated];
[self bottomScroll:self];
}
- (void)bottomScroll:(id)sender {
if (self.messages.count > 0)
[self.tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:self.messages.count-1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];
}
- (IBAction)sendReply:(id)sender {
[self bottomScroll:self];
}
messages.count絕對大於大於0時,該按鈕被竊聽 - 和斷點似乎表明該代碼被執行。超級奇怪。 –
你可以在一個乾淨的項目上重現你的問題嗎?我做了你正在嘗試一個新項目,它似乎工作正常。我能想到的最後一個問題是indexPath中的「section:0」部分。你確定這也是正確的嗎? – phi