gpt4 book ai didi

ios - touchesBegan 未被调用

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:22:20 31 4
gpt4 key购买 nike

我正在使用 UIPicker 来填充 UITextField 而不是键盘。这很好用,但我现在无法关闭 UIPicker。我希望能够点击屏幕上的任意位置并关闭 UIPicker。我已经尝试了每种触摸方法,但都不会触发。

设置用户交互启用:是。不确定这是否有所作为,但我使用的是 StoryBoard

我是否应该在我的 AppDelegate 中设置一些东西来监听触摸?

这是我的.h

 #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

这里是一些实现...

- (void)viewDidLoad
{
[super viewDidLoad];
[self.view setUserInteractionEnabled:YES];
[self buildBehaviorPicker];
NSLog(@"Member View");
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
NSLog(@"test");
[self.view touchesBegan:touches withEvent:event];
UITouch *touch = [touches anyObject];
int tCount = touch.tapCount;
NSLog(@"Touched %d", tCount);
}

- (void) buildBehaviorPicker
{
behaviorLevels = [[NSArray alloc] initWithObjects:@"Unsatisfactory", @"Needs Improvement", @"Satisfactory", @"Outstanding", nil];

UIPickerView *pickerView = [[UIPickerView alloc] init];
pickerView.dataSource = self;
pickerView.delegate = self;
[pickerView selectRow:2 inComponent:0 animated:NO];
self.behaviorTextField.inputView = pickerView;


}

提前致谢-鲍勃

最佳答案

您可以随时尝试以下操作:

-(void)viewDidLoad
{
[super viewDidLoad];

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapReceived:)];
[tapGestureRecognizer setDelegate:self];
[self.view addGestureRecognizer:tapGestureRecognizer];
}

-(void)tapReceived:(UITapGestureRecognizer *)tapGestureRecognizer
{
// do something, like dismiss your view controller, picker, etc., etc.
}

希望这有助于...

关于ios - touchesBegan 未被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24621402/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com