I have created two view controllers in XCode along with a UIPicker开发者_JAVA百科View, a label, a text view. I wanted to try and get data from the UIPickerView, so when the app detects that a row has been selected, it will automatically set the label to the value of the row in the UIPickerView. I also wanted certain descriptions for certain selected rows.
See some screenshots of my app here to further understand what it is I am trying to do;
1) http://cl.ly/102K3p2v433N0F1c0m2i - main screen
2) http://cl.ly/102K3p2v433N0F1c0m2i - selected row after lever has been "pulled"
3) http://cl.ly/2d1D2D1Z1s0k053Z2C3H - view controller pops up but the label/description still have default values
Here is my code;
1) (MAIN SCREEN) TroubleMakerViewController.h - http://pastie.org/2466793
2) (MAIN SCREEN) TroubleMakerViewController.m - http://pastie.org/2466795
3) (RESULTS SCREEN) Results.h - http://pastie.org/2466805
4) (RESULTS SCREEN) Results.m - http://pastie.org/2466808
Can somebody explain why the label and description text is showing the default text rather than what I have set it to do? Everything is linked up properly in the XIB files.
You need to implement the UIPickerViewDelegate method pickerView:didSelectRow:inComponent:
as described in the documentation to be notified as soon as the currently selected value changes. In this method just simply update the text of your label ;-)
精彩评论