gpt4 book ai didi

iphone - 有没有像scrollviewDidScroll这样的uipickerview委托(delegate)方法?

转载 作者:行者123 更新时间:2023-12-03 18:49:46 26 4
gpt4 key购买 nike

我有一个自定义的 UIPickerview,但我不想使用日期选择器。我想实现以下功能:当用户向下/向上滚动小时时,AM/PM 组件会在小时滚动时切换。这意味着我需要在调用 pickerView didSelectRow 之前切换它。有办法做到这一点吗?

谢谢

最佳答案

使用以下方法,

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// put your logic here.
}

以上方法来自UIPickerViewDelegate,如果用户使用pickerview选择任何元素,则会自动触发此方法。

希望对你有帮助。

编辑:

我认为你应该使用以下方法来检测 - 用户滚动的方向?

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
NSLog(@"scrolling to row is %@",[NSString stringWithFormat:@"index_%i",row]);
return [NSString stringWithFormat:@"index_%i",row];
}

每当用户向上/向下滚动时,都会自动触发上述方法,这与 UITableView 类似。请记住 UIPickerView 使用的是私有(private)的 UIPickerTableView,因此我们无法检测到您想要的滚动方式。

让我解释一下在pickerview中检测方向。

示例。可见行为 index_4、index_5、index_6、index_7。现在,如果用户向下滚动 index_8 将被调用。同样,如果用户向上滚动 index_3 将被调用。

希望这个技巧能解决您的问题。即使如此,请让我知道您对此的反馈。

关于iphone - 有没有像scrollviewDidScroll这样的uipickerview委托(delegate)方法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7625625/

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