使用Three20后,发现不能使用以前窗体里传递参数的方式了,因为窗体间的传递是由TTUrlMap在实现的,最终找到文章《Three20多参数映射TTUrlMap》(原文地址:
http://blog.csdn.net/diyagoanyhacker/article/details/6372633 )学习后了解了传递方式。
简单来说,在AppDelegate.m 中先将项目内的所有视图类文件全部引用进来,并且加入到TTUrlMap中。
例:一个有三个视图的工程,视图名称分别为:RootViewController,FirstViewController,SecondViewController
1、AppDelegate.m文件代码
#import "AppDelegate.h"
#import "RootViewController.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(UIApplication*)application {
TTNavigator* navigator = [TTNavigator navigator];
navigator.supportsShakeToReload = YES;
navigator.persistenceMode = TTNavigatorPersistenceModeAll;
TTURLMap* map = navigator.URLMap;
[map from:@"*" toViewController:[TTWebViewController class]];
[map from:@"tt://rootView" toSharedViewController:[RootViewController class]];
[map from:@"tt://firstView/(initWithName)" toViewController:[FirstViewController class]];
[map from:@"tt://secondView/(initWithType:)/(transValue:)" toViewController:[SecondViewController class]];
if (![navigator restoreViewControllers]) {
[navigator openURLAction:[TTURLAction actionWithURLPath:@"tt://rootView"]];
}
}
- (BOOL)application:(UIApplication*)application handleOpenURL:(NSURL*)URL {
[[TTNavigator navigator] openURLAction:[TTURLAction actionWithURLPath:URL.absoluteString]];
return YES;
}
2、RootViewController.m文件传递参数
- (void)createModel{
TTListDataSource* dataSource = [[[TTListDataSource alloc] init] autorelease];
[dataSource.items addObject:[TTTableTextItem itemWithText:@"Name"
URL:[NSString stringWithFormat:@"tt://firstView/%@", @"Jone"] ]]; //传递的参数不能是中文,否则接收时值会为nil
self.dataSource = dataSource;
}
3、接收参数的视图FirstViewController
1)、FirstViewController.h
-(id)initWithName:(NSString *)nameValue;
2)、FirstViewController.m
-(id)initWithName:(NSString *)nameValue{
self = [super init];
NSLog(@"获取传递的参数:%@", nameValue);
}
4、如果打开的是第三个视图SecondViewController
1)、FirstViewController.h
-(id)initWithType:(NSString *)typeValue transValue:(NSString *)transValue;
2)、FirstViewController.m
-(id)initWithType:(NSString *)typeValue transValue:(NSString *)transValue{
self = [super init];
NSLog(@"获取传递的参数1:%@ , 获取传递的参数2:%@", typeValue, transValue);
}
上面就是我理解的参数传递了。不过不能传中文是个头痛的事,谁有办法告诉我一下吧。