问题
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