First of all, I would like to say that I’m just beginning “learning” objective-c. Sorry if I’ve done big mistake
Im trying to delegate -(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row from view 2 to view 1…
inComponent:(NSInteger)component
View 1.h:
@interface ViewController : UIViewController <PopOverViewControllerDelegate>
View 1.m:
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component{ //stuff here}
View 2.h:
@protocol PopOverViewControllerDelegate <NSObject, UIPickerViewDelegate>
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component;
@end
@interface PopOverViewController : UIViewController <UIPickerViewDataSource>
View 2.m:
-(void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row
inComponent:(NSInteger)component{
[self.delegate pickerView:categoryPicker didSelectRow:row inComponent:component];
}
It does not work…
It’s a little strange for a view to be a delegate of another view. Views really shouldn’t know much about data — it’s the controller that usually makes the kinds of decisions that are required of a delegate.
Instead of having one delegate (View1) pass the picker’s delegate messages on to another delegate (View2), why not just make View2 the picker’s delegate? It seems like you’re making things more complicated than they need to be.
Please tell us more about the problem than “it does not work.” If it worked, you wouldn’t be asking in the first place. Tell us how it doesn’t work. Does the method in View2 ever get called? If yes, then what’s the problem? If no, why not? What happens in View1 that causes it not to call View2?