Making something happen when something is selected in a UIPickerView

前端 未结 1 1691
既然无缘
既然无缘 2021-01-29 05:47

I was working on creating an app that uses a UIPickerView. I made the view but I am trying to make a certain button change what it does. Please help.

1条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-29 06:25

    UIPickerView and many other controls use delegate pattern to inform you about events happening. To use it add to your class type definition(@interface line) and after that set the delegate of UIPickerView to your class like this:

    myUIPickerView.delegate = self;
    

    Then you can write the following method in your class and row is the index you want:

    - (void)pickerView:(UIPickerView *)pickerView
          didSelectRow:(NSInteger)row
           inComponent:(NSInteger)component
    {
        switch(row)
        {
             //...
        }
    }
    

    0 讨论(0)
提交回复
热议问题