我有一个隐藏的多个UIPickerView在静态应用程序中正常工作。但是,当我将它添加到具有滚动视图的应用程序时,当您离开选择器时它不再隐藏。
UIPickerView:
picker = [[UIPickerView alloc] initWithFrame:CGRectMake(100,100,400,160)];
picker.showsSelectionIndicator = TRUE;
picker.dataSource = self;
picker.delegate = self;
picker.hidden = YES;
[self.view addSubview:picker];
}
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
picker.hidden = YES;
}
我需要添加任何内容,因为它现在处于滚动视图中吗?
非常感谢
答案 0 :(得分:0)
通过在viewDidLoad:
之后添加这段代码解决了问题UITapGestureRecognizer *tapRec = [[UITapGestureRecognizer alloc]
initWithTarget:self action:@selector(tap:)];
[self.view addGestureRecognizer: tapRec];
}
-(void)tap:(UITapGestureRecognizer *)tapRec
{
[[self view] endEditing: YES];
// Hide picker
[picker resignFirstResponder];
picker.hidden = YES;
}