filipealva / PickerView

🔸 A customizable alternative to UIPickerView in Swift.
MIT License
527 stars 92 forks source link

Stuck in endless while loop, 0 rows for datasource. #36

Closed bvelasquez closed 6 years ago

bvelasquez commented 6 years ago

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)
}`
bvelasquez commented 6 years ago

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

filipealva commented 6 years ago

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.

filipealva commented 6 years ago

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