Crash Sometimes
Closed this issue · 4 comments
Hi !
I meet a strange problem that "sometimes" it will crash due to beyond the data array.
Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM objectAtIndex:]: index 2 beyond bounds [0 .. 1]'
and the " bounds[0..1] " will be different every time, sometimes it's [0..0], sometimes it's [0..2] and [0..3],
hope you can help me !
Hello!
Which version are you using? I tried to solve this problem in 0.2.2
but I don't know exactly when it occurs, so I'm not sure it is really solved.
Recently a documentation error was reported. Could you verify if you implemented the method below using index
as a reference instead of row
?
func pickerView(pickerView: PickerView, titleForRow row: Int, index: Int) -> String {
let item = itemsThatYouWantToPresent[index] // NOTE: Use `index` instead of `row` to retrieve your data correctly
return item.text
}
Until today earlier the docs were recommending to use row
instead of index
, maybe you implemented when the instructions were wrong.
I'm using PickerView
in two projects and I don't have this problem. I hope the tips above can help you
Thanks first !
I noticed that when i use it,still crash sometimes yesterday.So i debug it ,the problem is happened in the " if " sentence in "scrollViewDidScroll" function
tableView.cellForRowAtIndexPath(indexPath) as? SimplePickerTableViewCell
I think the problem maybe in some extreme conditions get the cell before reused it. because in "this case" ,DidScroll func run first than cellForRowAtIndexpath. And Today i run this project on my phone,it's only crash once.So strangely :(
And a small advice for this project,you can adjust this line in "ScrollViewWillEndDragging" into "scrollViewDidEndDecelerating"
delegate?.pickerView?(self, didSelectRow: currentSelectedRow, index: currentSelectedIndex)
because it's looks strange,the SelectedValue Changed before scroll to be selected.
Sorry, I was not able to reproduce this behavior.
@Hinsverson do you think that this behavior is related to #36?
Have you ever returned 0 as the number of rows on the data source?