我使用委託mehod在視圖控制器之間傳遞數據。這不起作用。委託方法不工作ios
@protocol PassCountry <NSObject>
@required
- (void) setPickedCountry:(NSString *)pickedCountry;
@end
@interface SelectCountryViewController : UIViewController<UIPickerViewDelegate, UIPickerViewDataSource> {
id <PassCountry> delegate;
}
@property (copy) NSString *pickedCountry;
@property (retain) id delegate;
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent (NSInteger)component {
pickedCountry = [self.countries objectAtIndex:row];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
return self.countries.count;
}
- (void)viewWillDisappear:(BOOL)animated {
[[self delegate] setPickedCountry:pickedCountry];
}
它究竟如何不工作? – Kreiri
你在哪裏調用這個委託方法,顯示代碼 –
你在哪裏設置委託,顯示代碼以及 – John