2014-10-30 186 views
12

我使用一个tableview中显示一条消息,我用下面[UITableView的_contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]

UIView *chatView = [self bubbleView:[NSString stringWithFormat:@"%@", message] from:YES]; 

[self.chatArray addObject:[NSDictionary dictionaryWithObjectsAndKeys:message, @"text", @"self", @"speaker", chatView, @"view", nil]]; 
[self.chatTableView reloadData]; 

[self.chatTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:[self.chatArray count]-1 inSection:0] 
           atScrollPosition: UITableViewScrollPositionBottom 
           animated:YES]; 

的代码和我得到以下

[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (0) beyond bounds (0) for section (0).' 

给出的错误plz帮助我在解决这个问题

+1

也许将'[NSIndexPath indexPathForRow:[self.chatArray count] -1 inSection:0]'设置为一个变量并在调用'scrollToRowAtIndexPath'之前检查它的值。确保所有值都是他们应该是的 – 2014-10-30 07:40:55

回答

14

在我看来,你的表视图还没有任何行或部分。我想到两种可能性。

  1. 检查numberOfRowsInSection代表和numberOfSectionsInTableView,使他们没有被设置为0。
  2. 它可能是tableview尚未完成加载数据。

请分享您的发现,以便我可以在需要时进一步提供帮助。

+0

@vinoad你究竟做了什么来解决这个问题? – Pawriwes 2017-08-07 19:42:04

+0

那么,他的问题是,他正试图在正确设置之前在表视图上执行操作,即它有任何行。所以,我认为他只是改变了这一点。 – Abdul91 2017-08-08 10:13:46