And*_*ark 5 iphone uipickerview delegatecommand
我有一个自定义的UIPickerview,我不想使用datepicker.我想实现这样的功能:当用户向下/向上滚动小时时,AM/PM组件在小时滚动时切换.这意味着我需要在调用pickerView didSelectRow之前切换它.有没有办法做到这一点?
谢谢
Sag*_*ari 13
使用以下方法,
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
// put your logic here.
}
Run Code Online (Sandbox Code Playgroud)
上面的方法来自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];
}
Run Code Online (Sandbox Code Playgroud)
每当用户向上/向下滚动时,方法会自动触发,类似于UITableView.记住UIPickerView使用的UIPickerTableView是私有的,因此我们无法以您想要的方式检测滚动.
让我解释一下检测pickerview中的方向.
例.可见行是index_4,index_5,index_6,index_7.现在,如果用户向下滚动index_8将被调用.同样,如果用户向上滚动index_3将被调用.
我希望这个技巧能解决你的问题.即使 - 请告诉我你对此的反馈.
有一个技巧可以检测到这一点,但没有委托方法/属性来检测它是否滚动
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String?或等效方法中将 isScrolling 设置为 truefunc pickerView(_ pickerView: UIPickerView, didSelectRow row: Int, inComponent component: Int)希望这会有所帮助,顺便说一句,这就是上述所有答案中的解释
| 归档时间: |
|
| 查看次数: |
7907 次 |
| 最近记录: |