了解TTNavigator

时间:2010-02-23 11:42:09

标签: iphone objective-c cocoa-touch three20

以下情况:

在TTTableViewController中,我添加了一些带URL的单元格。 例如,他们正以@"tt://photos"开设课程。这很好用。

首先,我在TT示例中看到了一些网址,例如@“tt / photos / 1”。是否有可能在我的照片类中获取此“1”并说,例如,好的,请打开图片1,ore是这个在TTNavigatior中宣布打开特定类的另一个URL吗?

另一件事是:是否可以将对象转发到链接类? 单击一个单元格打开@“tt:// photos”(我的TTNavigator中的链接类)

使用普通的tableviews我可以覆盖我的init方法并使用我的initialize方法发送一个对象,这也可以通过单击我的TTItems来实现吗?

谢谢!

4 个答案:

答案 0 :(得分:21)

自己想出来,对于那些需要它的人:

首先(在导航地图中传递“subURLs”)

可以使用@“tt:// photos / firstphoto”导航到网址,您可以像这样获取“firstphoto”:

//Prepare your Navigator Map like this
[map from:@"tt://photos/(initWithNumber:)" toViewController:[PhotoVC class]];

在您的PhotoVC中,您可以访问此号码:

-(void) initWithNumber: (NSString*)number {
    NSLog(@"%@",number);
}

使用此网址调用您的View Controller会显示:

PhotoVC* controller = [[PhotoVC alloc] initWithNumber:@"1"];
[navigationController pushViewController:controller animated:YES];
[controller release];

第二个(在TTTableViewController中传递对象)

它有点棘手,但你没有Subclass任何东西。

首先,没有TableItem中的URL

 [TTTableLink itemWithText:@"TTTableLink" URL:nil]
你的TTTableViewController中的

写下这个方法

- (void)didSelectObject:(id)object atIndexPath:(NSIndexPath*)indexPath {
     TTURLAction *urlAction = [[[TTURLAction alloc] initWithURLPath:@"tt://photos"] autorelease];
     urlAction.query = [NSDictionary dictionaryWithObject:@"firstphoto" forKey:@"photo"];
     urlAction.animated = YES;
     [[TTNavigator navigator] openURLAction:urlAction];
 }

现在在你的PhotoVC中你需要这样的东西

- (id)initWithNavigatorURL:(NSURL*)URL query:(NSDictionary*)query {
     if (self = [super init]) {
              NSLog(@"%@",query);
}

     return self;
}

你完成了;)

答案 1 :(得分:3)

我试图实现choise的答案,学到了很多东西,最终不得不让标注显示出来,并且让许多网址的实现保持简单,所以这就是我所做的。

  1. 将URL保留在TableItem中,

  2. 在TTTableViewController子类中使用此代码。

    - (void)didSelectObject:(id)object atIndexPath:(NSIndexPath*)indexPath {
    
          NSLog(@"Its url is %@", [object URL]);
    
          TTURLAction *urlAction = [[[TTURLAction alloc] initWithURLPath:(NSString *)[object URL]] autorelease];
    
          urlAction.query = [NSDictionary dictionaryWithObject:self.user forKey:@"user"];
    
          urlAction.animated = YES;
    
          [[TTNavigator navigator] openURLAction:urlAction];
    
     }
    
     - (BOOL)shouldOpenURL:(NSString*)URL {
    
         return NO;
    
     }
    
  3. 通过TTTableViewController发现了“shouldOpenURL:”,我试了一下,然后就可以了。现在表视图没有打开重复的视图,并且有标注!

  4. 谢谢你选择!

答案 2 :(得分:0)

虽然当你在代码中创建TTURLAction时,选择的答案适用于多个参数,但当你想在TTStyledLabel.One解决方案中嵌入链接到视图控制器时,它是非常有用的,即在单个字符串中使用多个参数。

<a href='app://view2/param1=value1&param2=value2&...'>LabelName</a>

如果您希望代码解析此类网址并获取参数,请随时向我发送消息,我将向您发送我的解析器类。 (或者您可以使用NSScanner构建自己的!)

也不要忘记逃避&amp; s,否则TTStyledLabel会不喜欢它!

答案 3 :(得分:0)

您不需要在TTTableViewController的当前版本1.0.6.2上运行它。 “URL”选项按预期工作。如果它不适合您,那么您的 URL 会被破坏,或者您在ViewController上调用了错误的函数。您必须通过 URL 调用的函数必须返回ViewController的id(是ViewController的构造函数)。然后它会按预期工作。

我会将示例表单 choise 改为像TTNavigator所期望的那样。

添加一个映射,TTNavigator将用于导航:

//Prepare your Navigator Map like this
[map from:@"tt://photos/(initWithNumber:)" toViewController:[PhotoVC class]];

创建一个带有URL集的TTTableLink(或TTStyledText或其他),这应该是你的地图:

[TTTableLink itemWithText:@"TTTableLink" URL:@"tt://photos/1"]

将此添加到您的PhotoVC,由TTNavigator在给定的URL上调用

-(id) initWithNumber: (NSString*)number {
    if (self = [super init]) {
        self.title = @"Some Title";

        NSLog(@"%@",number);
    }

    return self;       
}

您不需要覆盖函数 didSelectObject ,因为TTNavigator将通过定义的构造函数 tt:// photos /(initWithNumber :) <来调用ViewController / p>

相关问题