Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Here you go. UIPickerViews are a fairly complex system of nested UIViews which is why you weren't getting any response from the <code>touchesBegan:withEvent:</code> method. What you can do is create your UIPickerView subclass as follows:</p> <pre><code>// // MyPickerView.h // #import &lt;UIKit/UIKit.h&gt; // Protocol Definition that extends UIPickerViewDelegate and adds a method to indicate a touch @protocol MyPickerViewDelegate &lt;UIPickerViewDelegate&gt; // This is the method we'll call when we've received a touch. Our view controller should implement it and hide the keyboard - (void)pickerViewDidReceiveTouch:(UIPickerView *)pickerView; @end @interface MyPickerView : UIPickerView // We're redefining delegate to require conformity to the MyPickerViewDelegate protocol we just made @property (nonatomic, weak) id &lt;MyPickerViewDelegate&gt;delegate; @end // // MyPickerView.m // #import "MyPickerView.h" @implementation MyPickerView @synthesize delegate = _myPickerViewDelegate; // We changed the data type of delegate as it was declared in the superclass so it's important to link it to a differently named backing variable - (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event { // We make sure to call the super method so all standard functionality is preserved UIView *hitView = [super hitTest:point withEvent:event]; if (hitView) { // This will be true if the hit was inside of the picker [_myPickerViewDelegate pickerViewDidReceiveTouch:self]; } // Return our results, again as part of preserving our superclass functionality return hitView; } @end </code></pre> <p>Then in your ViewController change it to conform to <code>&lt;MyPickerViewDelegate&gt;</code> instead of <code>&lt;UIPickerViewDelegate&gt;</code>. This is ok since <code>MyPickerViewDelegate</code> inherits from <code>UIPickerViewDelegate</code> and will pass through the standard <code>UIPickerViewDelegate</code> methods.</p> <p>Finally implement <code>pickerViewDidReceiveTouch:</code> in your view controller:</p> <pre><code>- (void)pickerViewDidReceiveTouch:(UIPickerView *)pickerView { [enterInput resignFirstResponder]; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload