我所理解的Three20的多参数映射TTUrlMap

使用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);

上面就是我理解的参数传递了。不过不能传中文是个头痛的事,谁有办法告诉我一下吧。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值