我想知道如何通過委託傳遞2個字符串?我想從viewcontroller2(SelectStationViewController)傳遞給viewcontroller1(SubGabViewController)。通過委託傳遞2個字符串
我有它目前的工作,只是傳遞1個字符串(NSString *測試)。
下面的代碼我已成立:
// in SelectStationViewController.h
@protocol SelectStationViewControllerDelegate;
...
@interface ... {
id <SelectStationViewControllerDelegate> delegate;
}
@property (nonatomic, assign) id <SelectStationViewControllerDelegate> delegate;
@end
@protocol SelectStationViewControllerDelegate
- (void)selectStationViewControllerDidFinish:(NSString *)selectedStationName;
@end
// in SelectStationViewController.m
NSString *test = [[copyListOfItems objectAtIndex:indexPath.row] objectForKey:@"hash"];
[delegate selectStationViewControllerDidFinish:test];
// in SubGabViewController.h
@interface...<SelectStationViewControllerDelegate>
// in SubGabViewController.m
// set selectedStationName as currentStationName
- (void)selectStationViewControllerDidFinish:(NSString *)selectedStationName
{
NSLog(@"selectedStationName is = %@", selectedStationName);
[self setCurrentStationName:selectedStationName];
}
爲了通過2串委託,我會做這樣的事?
然後有另一個功能設置爲這樣?
- (void)selectStationViewControllerDidFinish:((NSString *)selectedStationName;
- (void)selectLineViewControllerDidFinish:((NSString *)selectedLineName;
完美。謝謝! – Aaron 2011-03-30 00:42:00
@Aaron:不客氣:-) – Oliver 2011-03-30 10:04:46