UIPickerView: get row value during rotation?

I would like to get the value of the row in real time, as the iPhone user rotates the wheel in the UIPickerView (not only when the wheel settles on a specific row). I looked at the UIPickerView subclass, then overriding the mouseDown method, but I could not get this to work. Any suggestions would be greatly appreciated.

+5
source share
3 answers

Perhaps try to implement the delegation method:

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view

( reusingView), , , , - , .

+10

UIPickerView . , , , UIView , , .

0

UIScrollView UIPickerView :

func findScrollView(view:UIView) -> UIScrollView? {
    if view is UIScrollView {
        return view as? UIScrollView
    }
    for subview in view.subviews {
        if subview is UIView {
            let result = findScrollView(subview as UIView)
            if result != nil {
                return result
            }
        }
    }
    return nil
}

UIScrollViewDelegate:

let scrollView = findScrollView(pickerView)
if scrollView != nil {
    scrollView!.delegate = self
}

And find the currently selected item:

func scrollViewDidScroll(scrollView: UIScrollView) {
    let offset = scrollView.contentOffset.y
    let index = Int(offset/itemHeight)
    if index >= 0 && index < items.count {
        let item = items[index]
        // do something with item
    }
}
0
source

All Articles