[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]

vin*_*inu 15 xcode objective-c uitableview ios

我正在使用tableview来显示消息,我使用下面的代码

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];
Run Code Online (Sandbox Code Playgroud)

我收到下面给出的错误

[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: row (0) beyond bounds (0) for section (0).'
Run Code Online (Sandbox Code Playgroud)

PLZ帮助我解决这个问题

Abd*_*l91 23

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

  1. 检查您的numberOfRowsInSection委托,numberOfSectionsInTableView以便它们不会设置为0.
  2. 可能tableview还没有完成加载数据.

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