Making something happen when something is selected in a UIPickerView

谁说我不能喝 提交于 2019-12-02 22:46:57

问题


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:


UIPickerView and many other controls use delegate pattern to inform you about events happening. To use it add <UIPickerViewDelegate> 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)
    {
         //...
    }
}


来源:https://stackoverflow.com/questions/34276692/making-something-happen-when-something-is-selected-in-a-uipickerview

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!