Ios 如何在viewcontroller中为子类pickerview实现selectedrow
我的故事板上有两个UIPickerViews,每个都是子类的,充当自己的数据源和委托。在我的子类中,我定义了行和列的数量,并给出了每个行和列的值/标签 我的主ViewController中有两个插座:Ios 如何在viewcontroller中为子类pickerview实现selectedrow,ios,objective-c,uiviewcontroller,delegates,uipickerview,Ios,Objective C,Uiviewcontroller,Delegates,Uipickerview,我的故事板上有两个UIPickerViews,每个都是子类的,充当自己的数据源和委托。在我的子类中,我定义了行和列的数量,并给出了每个行和列的值/标签 我的主ViewController中有两个插座: @property (weak, nonatomic) IBOutlet PickerView1 *pv1; @property (weak, nonatomic) IBOutlet PickerView2 *pv2; 我想使用委托方法 -(void)pickerView:(UIPickerVi
@property (weak, nonatomic) IBOutlet PickerView1 *pv1;
@property (weak, nonatomic) IBOutlet PickerView2 *pv2;
我想使用委托方法
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
触发主视图上信息的更新。但问题是主ViewController不是这两个视图的委托(无论如何,不能同时为这两个视图提供委托),并且我看不到与UIPickerView相关的iActions。上面的方法将在我的子类(它自己的委托)中调用,我不知道如何将此操作返回到我的主viewcontroller
所以我的问题是,有没有办法让子类中的“didSelectRow”在我的主ViewController中触发一个操作?你可以编写一个协议,但在UIKit中有一个协议,它具有你想要的确切方法,在我看来,阻力最小的路径是这样的
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
if (pickerView == self.pv1){
//respond to PV1..
}else{
//respond to PV2..
}
}