IOS development diary 48-UIPickerView, 48-uipickerview

Source: Internet
Author: User
Tags uicontrol

IOS development diary 48-UIPickerView, 48-uipickerview

Today, the blogger has a UIPickerView requirement and encountered some difficulties. I would like to share with you the hope to make common progress.

UIPickerView is a selector control, which is more common than UIDatePicker. It can generate Single-Column selector or multiple-column selector, and developers can customize the appearance of selected items, therefore, the usage is flexible.

UIPickerView inherits UIView and does not inherit UIControl. Therefore, it cannot bind an event processing method as UIControl does. UIPickerView event processing is completed by its delegate object.

Self. viewOfPick = [[UIPickerView alloc] initWithFrame: CGRectMake (100, 0,200, [UIScreen mainScreen]. bounds. size. height)];

_ ViewOfPick. dataSource = self;

_ ViewOfPick. delegate = self;

// PickerView the row is selected as 0 by default, and wireless scrolling only displays the Middle Value of the row at the beginning, resulting in the illusion of wireless scrolling.

[_ ViewOfPick selectRow: 9 inComponent: 0 animated: YES];

// Set pickerView to select the last row by default

[_ ViewOfPick selectRow: 9 inComponent: 1 animated: YES];

[Self. view addSubview: _ viewOfPick];

// Similar to the cell for row of tableView, the returned string is displayed based on row and component.

-(Nullable NSString *) pickerView :( UIPickerView *) pickerView titleForRow :( NSInteger) row forComponent :( NSInteger) component _ TVOS_PROHIBITED

{

Return @ "null ";

}

// Similar to didSelect of tableView, perform specific value passing operations based on row and component.

-(Void) pickerView :( UIPickerView *) pickerView didSelectRow :( NSInteger) row inComponent :( NSInteger) component _ TVOS_PROHIBITED

{

NSLog (@ "*********** % ld, % ld", (long) component, row );

}

// Similar to the cell for row of tableView, the custom View display is returned Based on row and component.

// Note: At the same time, NSString is returned and the following method for returning UIView is returned. Only the method for returning UIView is executed.

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

{

UIView * blackView = [[UIView alloc] initWithFrame: CGRectMake (0, 0, 10, 10)];

BlackView. backgroundColor = [UIColor blackColor];

Return blackView;

}

// Returns the Row Height of the pickerView.

-(CGFloat) pickerView :( UIPickerView *) pickerView rowHeightForComponent :( NSInteger) component _ TVOS_PROHIBITED

{

Return 40;

}

// Returns the number of 'columns 'to display. component quantity

-(NSInteger) numberOfComponentsInPickerView :( UIPickerView *) pickerView

{

Return 2;

}

 

// Returns the # of rows in each component .. row quantity

-(NSInteger) pickerView :( UIPickerView *) pickerView numberOfRowsInComponent :( NSInteger) component

{

Return 10;

}

 

 

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.