Click the UIPickerView listener button.

Source: Internet
Author: User

Click the UIPickerView listener button.

We use pickview when selecting a region, for example. When you use it, select the corresponding region and click OK or cancel to end the editing. However, if we do this:

UIPickerView * pick = [[UIPickerView alloc] init];

[Pick addSubview: cancel_btn];

[Pick addSubview: OK _btn];

Effect:

   

When you click the button, it is found that the click event is listened by pickview, and the button cannot receive the event. Therefore, this method is unavailable.

Of course, you can also click on the area selection, we will pop up a mask, then add pickview, cancel_btn and OK _btn to the mask, and then click the listener button to pass the selected data to the Controller. this method is feasible, but it is difficult to think about it and is not recommended.

We recommend that you use the following method:

Remember that UITextField has an inputView attribute, which controls the view popped up by clicking field. What we need to do is field. inputView = pickView;

The point is, how do I put the buttons? We define a UITextField. The field has an attribute called inputAccessoryView, which adds an auxiliary View to the field pop-up view, at this time, we only need to add the button to this secondary view.

UIToolbar * tool = [[UIToolbar alloc] init];

Tool. frame = CGRectMake (0, 0, 0, 44 );

[Tool addSubview: cancel_btn];

[Tool addSubview: OK _btn];

Field. inputAccessoryView = tool;

You only need to add the button in the layoutSubviews method.

Then the effect is as follows:

  

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.