我正在尝试做的事情:
我有一个ViewController
:
@implementation ViewController
@synthesize myPicker;
@synthesize myPickerHelper;
@synthesize label;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
myPickerHelper = [[UIPickerViewHelper alloc]initWithUIPickerView:myPicker andNumberOfComponents:4];
[myPickerHelper.valuesForComponent1 addObject:@"TEST1"];
[myPickerHelper.valuesForComponent1 addObject:@"TEST2"];
;
[weightsPicker reloadAllComponents];
[weightsPicker selectRow:0 inComponent:0 animated:YES];
//TODO receive message from picker helper.
//label.text = ... set a listner (like that one in java) or what else
}
}
我有一个PickerViewHelper
:(处理委托和数据源问题)
@interface UIPickerViewHelper : NSObject <UIPickerViewDelegate, UIPickerViewDataSource, OnPickerViewChangeDelegate>
@implementation UIPickerViewHelper
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
//TODO send message to controller view.
}
和协议:
@protocol OnPickerViewChangeDelegate
@optional
-(void)onChange:(NSString*)result;
@end
我想要的是在我的UiPickerViewHelper
类中使用协议方法“onChange”,以便通知我的标签(在我的 ViewController 中)。我知道如何在 Java 中解决这个问题,但我不知道如何在目标 c 中解决这个问题。
问候