ios - touchesBegin 没有被调用
<p><p>我使用 UIPicker 来填充 UITextField 而不是键盘。这很好用,但我现在无法关闭 UIPicker。我希望能够点击屏幕上的任意位置并关闭 UIPicker。我已经尝试了每种触摸方法,但都不会触发。 </p>
<p>setUserInteractionEnabled:是的。
不确定它是否有区别,但我使用的是 StoryBoard</p>
<p>我应该在我的 AppDelegate 中设置一些东西来监听触摸吗?</p>
<p>这是我的 .h</p>
<pre><code> #import <UIKit/UIKit.h>
@interface RNMemberTableViewController : UITableViewController<UIPickerViewDataSource, UIPickerViewDelegate, UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UIPickerView *behaviorPicker;
@property (nonatomic, weak) IBOutlet UIDatePicker *dateOfRecordPicker;
@property (nonatomic, strong) NSArray *behaviorLevels;
@property (weak, nonatomic) IBOutlet UITextField *behaviorTextField;
@end
</code></pre>
<p>这里是一些实现...</p>
<pre><code>- (void)viewDidLoad
{
;
;
;
NSLog(@"Member View");
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"test");
;
UITouch *touch = ;
int tCount = touch.tapCount;
NSLog(@"Touched %d", tCount);
}
- (void) buildBehaviorPicker
{
behaviorLevels = [ initWithObjects:@"Unsatisfactory", @"Needs Improvement", @"Satisfactory", @"Outstanding", nil];
UIPickerView *pickerView = [ init];
pickerView.dataSource = self;
pickerView.delegate = self;
;
self.behaviorTextField.inputView = pickerView;
}
</code></pre>
<p>提前致谢
-鲍勃</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>您可以随时尝试以下方法:</p>
<pre><code>-(void)viewDidLoad
{
;
UITapGestureRecognizer *tapGestureRecognizer = [ initWithTarget:self action:@selector(tapReceived:)];
;
;
}
-(void)tapReceived:(UITapGestureRecognizer *)tapGestureRecognizer
{
// do something, like dismiss your view controller, picker, etc., etc.
}
</code></pre>
<p>希望这会有所帮助...</p></p>
<p style="font-size: 20px;">关于ios - touchesBegin 没有被调用,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24621402/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24621402/
</a>
</p>
页:
[1]