UIPicker 选择行
我正在尝试选择第一行作为默认值.. 在这里,我尝试了
-(void)pickerViewLoaded{
[pickerView setShowSelectionIndicator:YES];
pickerView.delegate = self;
[pickerView reloadAllComponents];
[pickerView selectRow:1 inComponent:0 animated:YES]
}
当我在 viewDidLoad() 上调用此方法(它调用 didSelectRow 方法)时效果很好,但它选择的是该组件的第二行而不是第一行。 当我使用 [pickerView selectRow:0 inComponent:0animated:YES] 调用时,它永远不会调用 didSelectRow 方法。
另一个问题是当我在选择分段控件时调用 pickerViewLoaded 方法时,它不会调用 didSelectRow 方法。我仍然不知道什么时候它可以使用viewDidLoad调用,那么为什么不使用segmentedControl呢?
谢谢大家,
I am trying to select the first row as default..
Here i tried
-(void)pickerViewLoaded{
[pickerView setShowSelectionIndicator:YES];
pickerView.delegate = self;
[pickerView reloadAllComponents];
[pickerView selectRow:1 inComponent:0 animated:YES]
}
It works fine when i call this method on viewDidLoad() which call didSelectRow method but it is selecting the second row of that component not first one.
when i call with [pickerView selectRow:0 inComponent:0 animated:YES] then it never call didSelectRow method.
another problem is when i call pickerViewLoaded method on selection of segmented control it does not call the didSelectRow method. i still could not figure when it may call with viewDidLoad then why not with segmentedControl.
Thanks all,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
似乎是一个老线程,无论如何我想分享我的经验。
我遇到了同样的问题,并
。
仅在使用通知返回最后一行调用的 titleForRow 后才将其移至我调用 selectRow:inComponent:animated
seems to be a old thread, anyway I thought of sharing my experience.
I had the same issue and moved the
to
I call the selectRow:inComponent:animated only after returning the titleForRow called for last-row using a notification.
现在问题已经从死里复活了...
我认为 selectRow 使用从 0 开始的索引,而不是 1。所以 0 是第一行,1 是第二行。
Now that the question has been raised from the dead...
I think selectRow uses an index that starts at 0 - not 1. So 0 is the first row, and 1 is the second row.
我刚刚遇到了同样的问题并解决了这个问题:如果所选行没有更改,则不会调用委托。此外,默认情况下会选择第 0 行,因此在
viewDidLoad
中重新选择第 0 行不会触发委托。就我而言,我能够直接调用委托方法,也许这也是您的情况的解决方案。I just ran into the same problem and figured it out: The delegate doesn't get called, if the selected row doesn't change. Also, row 0 is selected by default, so re-selecting row 0 in
viewDidLoad
doesn't trigger the delegate. In my case I was able to call the delegate method directly, maybe that's the solution in your case, too.