IOS learning notes-simple use of UIPickerView Control
UIPickerView is one of the commonly used controls in iOS. It provides a series of multi-value options through the rotation interface. It displays information to users and collects user input. The following is a common UIPickerView control.
The UIPickerView control must comply with two Protocols:UIPickerViewDelegate, The other isUIPickerViewDataSource.
UIPickerViewDelegateThe Protocol methods include:
1.-(NSString *) pickerView: (UIPickerView *) pickerView
TitleForRow: (NSInteger) row <喎?http: www.bkjia.com kf ware vc " target="_blank" class="keylink"> VcD4KPHA + signature + cjxwp?vcd4kpha + signature/K/TwvcD4KPHA + signature + signature + signature/LqstuDJ2dDQoaM8L3A + signature + cjxwp?vcd4kpha + signature/TwvcD4KPHA + signature + Signature signature + signature + 86vzdC3vbeozrTKtc/WLLvy1d/Signature + signature + cve-vcd4kpha + yr7A/bt6wuujuw.vcd4kpha + expires "brush: java; "> @ interface TBLViewController: UIViewController {NSArray * firstTypes; NSArray * secondTypes;} @ property (strong, nonatomic) IBOutlet UIPickerView * pickerView;-(IBAction) Sure :( id) sender; @ end
Text. m
-(Void) viewDidLoad // initialize {[super viewDidLoad]; firstTypes = [[NSArray alloc] initWithObjects: @ "hello", @ "hi", @ "how are u ", nil]; secondTypes = [[NSArray alloc] initWithObjects: @ "Zhao", @ "Qian", @ "Sun", @ "Li", @ "Zhou ", @ "Wu", @ "Zheng", @ "Wang", nil]; pickerView. delegate = self;}-(void) didReceiveMemoryWarning {[super didreceivemorywarning];}-(IBAction) Sure :( id) sender {// display selected information NSInteger first = [pickerView selectedRowInComponent: 0]; // NSInteger second = [pickerView selectedRowInComponent: 1]; NSString * firstString = [firstTypes objectAtIndex: first]; // The information of the selected row NSString * secondString = [secondTypes objectAtIndex: second]; NSString * message = [NSString stringWithFormat: @ "Your chooise is % @ & % @", firstString, secondString]; UIAlertView * alert = [[UIAlertView alloc] initWithTitle: @ "Chooise Information" message: message delegate: nil cancelButtonTitle: @ "OK" otherButtonTitles: nil]; [alert show] ;}# pragma mark-# pragma mark Picker Data Source Methed-(NSInteger) numberOfComponentsInPickerView :( UIPickerView *) pickerView {// return the number of columns return 2;}-(NSInteger) pickerView :( UIPickerView *) pickerView numberOfRowsInComponent :( NSInteger) component {// return the number of rows in this column if (component = 0) {return [firstTypes count];} else {return [secondTypes count] ;}# pragma mark Picker Delegate Methods-(NSString *) pickerView :( UIPickerView *) pickerView titleForRow :( NSInteger) row forComponent :( NSInteger) component {// return the row title if (component = 0) {return [firstTypes objectAtIndex: row];} else {return [secondTypes objectAtIndex: row];} @ end