首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >未调用touchesBegan

未调用touchesBegan
EN

Stack Overflow用户
提问于 2014-07-08 07:15:36
回答 3查看 16.6K关注 0票数 2

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

setUserInteractionEnabled:可以。我不确定这是否有区别,但我使用的是StoryBoard

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

这是我的.h

代码语言:javascript
复制
 #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

下面是一些实现。

代码语言:javascript
复制
- (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;


}

预先感谢-Bob

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2014-07-08 22:41:16

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

代码语言:javascript
复制
-(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.
}

希望这能帮到你。

票数 7
EN

Stack Overflow用户

发布于 2014-07-08 10:58:32

您可以在选取器下添加一个与控制器视图大小相同的透明按钮。

显示选取器时设置button.hidden = NO,隐藏选取器时设置button.hidden = YES

有几种方法可以隐藏选择器。最简单的方法是设置picker.hidden = YES

票数 -1
EN

Stack Overflow用户

发布于 2015-07-23 18:43:23

如果您使用的是UIScrollView,那么

代码语言:javascript
复制
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event

将不会被调用,因为touchesBegan是UIView的方法而不是UIScrollView的方法。

票数 -5
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/24621402

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档