【问题标题】:UIPicker selectRowUIPicker 选择行
【发布时间】:2010-08-18 15:16:09
【问题描述】:

我正在尝试选择第一行作为默认值.. 这里我试过了

-(void)pickerViewLoaded{

   [pickerView setShowSelectionIndicator:YES];
   pickerView.delegate = self;
   [pickerView reloadAllComponents];
   [pickerView selectRow:1 inComponent:0 animated:YES]
}

当我在调用 didSelectRow 方法的 viewDidLoad() 上调用此方法时,它工作正常,但它选择的是该组件的第二行而不是第一行。 当我使用 [pickerView selectRow:0 inComponent:0 animated:YES] 调用时,它永远不会调用 didSelectRow 方法。

另一个问题是,当我在选择分段控件时调用 pickerViewLoaded 方法时,它不会调用 didSelectRow 方法。我仍然不知道它何时可以使用 viewDidLoad 调用,那么为什么不使用 segmentedControl。

谢谢大家,

【问题讨论】:

    标签: iphone objective-c uipickerview uipickerviewcontroller


    【解决方案1】:

    好像是老帖子了,反正我是想分享一下我的经验。

    我有同样的问题并移动了

    [pickerView selectRow:0 inComponent:0 animated:YES];
    

    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
    

    只有在使用通知返回最后一行调用的 titleForRow 后,我才调用 selectRow:inComponent:animated

    【讨论】:

      【解决方案2】:

      现在问题已经从死里提出来了……

      我认为 selectRow 使用从 0 开始的索引,而不是 1。所以 0 是第一行,1 是第二行。

      【讨论】:

        【解决方案3】:

        我刚刚遇到了同样的问题并想通了:如果选定的行没有更改,则不会调用委托。此外,默认选择第 0 行,因此在 viewDidLoad 中重新选择第 0 行不会触发委托。就我而言,我可以直接调用委托方法,也许这也是您的解决方案。

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2013-11-25
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多