【发布时间】:2011-03-29 23:50:36
【问题描述】:
我想知道如何通过我的委托传递 2 个字符串?我想将它从 viewcontroller2 (SelectStationViewController) 传递给 viewcontroller1 (SubGabViewController)。
我目前正在使用它,只传递了 1 个字符串 (NSString *test)。
这是我设置的代码:
// 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 个字符串传递给委托,我会做这样的事情吗?
// in SelectStationViewController.m
NSString *test = [[copyListOfItems objectAtIndex:indexPath.row] objectForKey:@"hash"];
NSString *test2 = [[copyListOfItems objectAtIndex:indexPath.row] objectForKey:@"linehash"];
[delegate selectStationViewControllerDidFinish:test];
[delegate selectLineViewControllerDidFinish:test2];
然后像这样设置另一个功能?
- (void)selectStationViewControllerDidFinish:((NSString *)selectedStationName;
- (void)selectLineViewControllerDidFinish:((NSString *)selectedLineName;
【问题讨论】:
标签: iphone delegates uiviewcontroller