我使用委托方法在视图控制器之间传递数据。这是行不通的。
@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];
}