我想知道如何通过委托传递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