IOS learning notes-simple use of UIPickerView Control

Source: Internet
Author: User

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.