filipealva/PickerView

Stuck in endless while loop, 0 rows for datasource.

Closed this issue · 3 comments

In the PickerView.swift, I am in an endless loop here, which locks up my app. I'm returning 0 for the pickerViewNumberOfRows delegate, because the user has not yet entered any data. I set the delegate and datasource in viewDidLoad().

`fileprivate func selectedNearbyToMiddleRow(_ row: Int) {
currentSelectedRow = row
tableView.reloadData()

    repeat {
        // This line adjust the contentInset to UIEdgeInsetZero because when the PickerView are inside of a UIViewController 
        // presented by a UINavigation controller, the tableView contentInset is affected.
        tableView.contentInset = UIEdgeInsets.zero
        
        let indexOfSelectedRow = visibleIndexOfSelectedRow()
        tableView.setContentOffset(CGPoint(x: 0.0, y: CGFloat(indexOfSelectedRow) * rowHeight), animated: false)
        
        delegate?.pickerView?(self, didSelectRow: currentSelectedRow, index: currentSelectedIndex)
        
    } while !(numberOfRowsByDataSource > 0 && tableView.numberOfRows(inSection: 0) > 0)
}`

I've worked around this by always returning 1, and just returning "" in the titleForRow if my data array is empty.

Good catch!

This case of use have never happened to me, but it maybe is related to #14.

Thanks for reporting, really appreciate this insight, I'll think about how to fix it and as soon I have some idea I'll deploy a release and let you know.

@bvelasquez It's fixed. I'll release it soon, but you can already point it to master.