【问题标题】:three20 - can the query added to an openURLAction also be passed back to the parentthree20 - 添加到 openURLAction 的查询是否也可以传递回父级
【发布时间】:2010-03-03 09:29:59
【问题描述】:

我正在设置到 TTTableViewController 的路由,如下所示:

[map from:@"myurl://filter/(initWithName:)" 
      toViewController:[FilterViewController class]];

然后,在另一个视图控制器中,我设置了一个可变字典作为我的查询传递:

// Set up dictionary and populate a field
NSMutableDictionary *filterDictionary;
filterDictionary = [[NSMutableDictionary alloc] init];
[filterDictionary setObject:@"test entry" forKey:@"test key"];

// Attach a query to the URL and open it
TTURLAction *theAction = [[TTURLAction actionWithURLPath:@"myurl://filter/search"] 
          applyQuery:filterDictionary];
[[TTNavigator navigator] openURLAction:theAction];

最后,在过滤视图控制器中,我可以正确访问这些值:

在.h中:

@property (nonatomic, retain) NSMutableDictionary *filterDictionary;

在.m:

- (id)initWithName:(NSString *)filterName query:(NSMutableDictionary *)filters {
 if (self = [self init]) {
  self.filterDictionary = filters;
  NSLog(@"Filter Dictionary assigned : %@", self.filterDictionary);
 }
 return self;
}

- (BOOL)textFieldShouldReturn:(UITextField *)textField {
 if (filterDictionary) 
        [filterDictionary setObject:textField.text forKey:@"searchAddress"];
 [textField resignFirstResponder];
 return YES;
}

字典是正确可变的,我可以毫无问题地添加值等。但是,当我的 filterViewController 被关闭时,我认为更改后的字典将反映在父级中 - 它是通过引用正确传递的。

我错过了什么吗?由于某处的基类 Three20,我在 filterVC 中的字典实际上是副本吗?

【问题讨论】:

    标签: url-routing three20


    【解决方案1】:

    我遇到了类似的问题。我怀疑我们可能需要传入一个委托(通过该查询),以及您的字典作为一个单独的对象。然后让父级遵守这个新 VC 中定义的协议,您现在可以在适当的时间传回该字典。

    TTNavigator 还具有 viewControllerForURL:query: (以及其他)用于在不打开它的情况下获取 VC,但也许传入查询并让 VC “做正确的事情”就足够了,而且我认为 - 强调思考 -想法是开始使用 URL 操作,而不仅仅是 URL(在 Three20 的意义上)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-11-02
      • 1970-01-01
      • 2015-01-08
      • 2021-06-23
      • 2013-09-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多