Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
bvelasquez opened this issue Oct 5, 2017 · 3 comments
Closed

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

bvelasquez opened this issue Oct 5, 2017 · 3 comments

Comments

@bvelasquez
Copy link

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 bvelasquez reopened this Oct 5, 2017
@bvelasquez
Copy link
Author

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

@filipealva
Copy link
Owner

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
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants