Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

[UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]

I am using a tableview to display a message and i used the code below

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];

And i am getting the error given below

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

plz help me in solving this

like image 592
vinoad vinu Avatar asked Oct 30 '14 07:10

vinoad vinu


2 Answers

Seems to me that your table view does not have any rows or sections in yet. Two possibilities come to my mind.

  1. Check your numberOfRowsInSection delegate and numberOfSectionsInTableView so that they are not set to 0.
  2. Its possible that the tableview has not yet finished loading the data.

Do share your findings, so I might be able to help out further if needed.

like image 176
Abdul91 Avatar answered Nov 03 '22 21:11

Abdul91


Make sure your table view is getting reloaded before scrolling. because after adding the data in the array, we need to reload the data to populate the TableView cell.

like image 1
Alok Avatar answered Nov 03 '22 20:11

Alok