gpt4 book ai didi

iphone - 点击选定行时关闭 UIPickerView

转载 作者:行者123 更新时间:2023-11-29 11:09:36 27 4
gpt4 key购买 nike

我正在使用 UIPickerView 让用户从几个选项中进行选择,当我显示选择器时,我滚动到最后选择的行。

当用户选择一行时,我希望始终关闭选择器(即使用户点击已经选择的行),我在 didSelectRow 方法中关闭选择器。

问题是,如果用户重新选择所选行,则不会调用 didSelectRow 方法,因此我无法关闭选择器..

最佳答案

一种解决方案是创建 UIPickerView 的子类并覆盖 touchesEnded:withEvent: 方法:

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesEnded:touches withEvent:event];
// dismiss the picker view here, either directly, or you could notifiy
// the delegate with a custom message:
if ([self.delegate respondsToSelector:@selector(pickerViewShouldDismiss:)]) {
[self.delegate pickerViewShouldDismiss:self];
}
}

或者您可以添加 UITapGestureRecognizerUIPickerView:

UITapGestureRecognizer *tapGR = [UITapGestureRecognizer alloc] initWithTarget:self
action:@selector(pickerViewTapped];
[pickerView addGestureRecognizer:tapGR];

然后:

- (void)pickerViewTapped {
// dismiss the picker.
}

我不是 100% 确定这不会干扰 UIPickerView 处理点击的方式。

关于iphone - 点击选定行时关闭 UIPickerView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12131426/

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