Reputation: 1213
UITableView _contentOffsetForScrollingToRowAtIndexPath:atScrollPosition:]: section (3) beyond bounds (1).'
I've got an array of information being displayed at my tableview, and when I hit a button I'm wanting it to scroll down to a certain cell.
Initially I thought I was getting that error because of the way I was getting my index to jump to:
if let index = peopleListArray.index(where: { $0.UID == currentUser }) {
print(index)
let NSIndex = NSIndexPath(index: Int(index) )
tableView.reloadData()
print(peopleListArray.count)
print(NSIndex)
tableView.scrollToRow(at: NSIndex as IndexPath , at: .top, animated: true )
}
But then I replaced "let NSINDex... with
let NSIndex = NSIndexPath(index: 1 )
and it's still throwing the same error.
when I'm printing out my array count and my NSIndex I'm always getting an 8 for the count (which is correct) and I'm getting 3 for the NSINdexPath which is correct.
I could understand the error if the 3 was out of bounds of my array.count but it definitely isn't.
any ideas?
Upvotes: 0
Views: 1996
Reputation: 27
There are two options that may be wrong here:
you passed a section that is out of bounds, i.e with index less than 0 or bigger than the specified number of sections in
numberOfSectionsInTableView:(UITableView *)tableView
So just try to use 0 for the section number first.
Upvotes: -1
Reputation: 613
It seems the issue you are having is with the section and not with the row. Try to build the index like this:
NSIndexPath(item: index, section: 0)
Note the section is set to 0.
Upvotes: 2