简体   繁体   中英

Drawing the UIPicker values from multiple components?

I have the UIPicker setup with multiple components and a button below it. Depending on what the user has chosen with the UIPicker determines which new view will be loaded but I am having trouble determining how to extrapolate the information from the picker itself. Right now I have this method being called when the button is pressed:

- (IBAction) buttonPressed {
        if (component:1 == 1 && component:2 == 1) {
                //Load the view number 1.
        } else if (component:1 == 2 && component:2 == 1) {
                //Load the view number 2.
        } else {
                //Load the view number 3.
        }
}

I obviously know that my code is wrong but I hope it gets the point across. I have multiple components and I need to figure out how to use the information that the user is scrolling to on the picker to determine which view to move to. (I know how to load the views, I just commented those in the code to illuminate the problem areas better.)

How do I go about using the pickerViews to extrapolate the information IN the buttonPressed IBAction method?

To respond directly to picker manipulation, use the delegate's pickerView:didSelectRow:inComponent: .

To obtain the view corresponding to user selection, use viewForRow:forComponent: . From that view you can obtain information about what it displays (if it's a UILabel, inspect its text property).

Also, you can obtain this information directly from the data source, referring to the piece of information you would return in the delegate's pickerView:titleForRow:forComponent: or pickerView:viewForRow:forComponent:reusingView: , for the currently selected row and component.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM