如果用户在其他地方点击 UIPickerView,如何让 UIPickerView resignFirstResponder [英] How to make UIPickerView resignFirstResponder if user clicks in other place then UIPickerView

查看:25
本文介绍了如果用户在其他地方点击 UIPickerView,如何让 UIPickerView resignFirstResponder的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了 UIPickerView 如下.现在我想让它 resignFirstResponder 如果用户点击其他地方然后 UIPickerView 我怎么能做到这一点.我已经按照以下方式创建了 UIPickerView.我还能在哪里处理

I have created UIPickerView as following . Now i want to make it resignFirstResponder if user clicks in other place then UIPickerView How could i achieve that. I have created the UIPickerView as following way.Where else could I handle

[pickerView removeFromSuperview];

-(void)pickerview:(id)sender
{
    _items =[[NSArray alloc]initWithObjects:@"Hindi",@"English",@"In what city were you born?",
             @"What was your childhood nickname?",
             @"Type your own question.",nil];

    pickerView=[[UIPickerView alloc] initWithFrame:CGRectMake(10,350,300,300)];

    pickerView.transform = CGAffineTransformMakeScale(0.75f, 0.75f);
    pickerView.delegate = self;
    pickerView.dataSource = self;
    pickerView.showsSelectionIndicator = YES;
    pickerView.backgroundColor = [UIColor lightGrayColor];
    [pickerView selectRow:1 inComponent:0 animated:YES];
  //  [self.view addSubview:pickerView];
    [contentView addSubview:pickerView];


}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{

    return 1;

}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{

    return [_items count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
        return[_items objectAtIndex:row];

}

-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
    [Txt_SecurityQue setText:[_items objectAtIndex:row]];
     NSLog(@"Did select");
}

推荐答案

-(void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:YES];

    UITapGestureRecognizer *tap=[[UITapGestureRecognizer          
     alloc]initWithTarget:self action:@selector(Tap)];
    [contentView addGestureRecognizer:tap];
}

-(void)Tap {

   //write the UIPickerView resignFirstResponder code......
}

这篇关于如果用户在其他地方点击 UIPickerView,如何让 UIPickerView resignFirstResponder的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆