gpt4 book ai didi

ios - 如果用户在其他地方单击然后 UIPickerView,如何使 UIPickerView resignFirstResponder

转载 作者:行者123 更新时间:2023-11-28 18:58:03 26 4
gpt4 key购买 nike

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

[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......
}

关于ios - 如果用户在其他地方单击然后 UIPickerView,如何使 UIPickerView resignFirstResponder,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29814658/

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