Three20 - 打开共享视图控制器的 url
我知道如果使用 from:toViewController:
映射一个 url,然后打开该 url 将创建一个新的视图控制器,如果使用 from:toSharedViewController
则将创建一个共享实例用过的。
但是例如
[map from:@"tt://tabbar/(initWithString:)" toSharedViewController:[MyTabbarController class]];
TTOpenURL(@"tt://tabbar/string");
这将调用类似的内容
[[MyTabbarController alloc] initWithString:@"string"]
但是如果稍后调用 TTOpenURL(@"tt://tabbar/somethingelse") 会发生什么? 由于使用了共享对象,因此 initWithString:
是否会在同一个实例上调用两次?
I know that if map a url with from:toViewController:
, then open that url will create a new view controller and if from:toSharedViewController
is used then a shared instance will be used.
But for example
[map from:@"tt://tabbar/(initWithString:)" toSharedViewController:[MyTabbarController class]];
TTOpenURL(@"tt://tabbar/string");
This will invoke something similar to
[[MyTabbarController alloc] initWithString:@"string"]
But what will be happened if TTOpenURL(@"tt://tabbar/somethingelse")
in called later?
Since a shared object is used so will the initWithString:
be called twice on a same instance?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
答案是:不。即,不会在已初始化的实例上调用 init,但将分配并初始化一个新实例。
这是由于 Three20 将对象关联到其完整 URL,在您的情况下是“tt://tabbar/string”或“tt://tabbar/somethingelse”,因此在查询
TTURLMap,不会找到已经存在的对象,并且将实例化一个新对象。至少,从 Three20 1.0.3 开始是这样。但我想他们并没有改变这一点。
在我看来,共享控制器机制适用于非常特殊的情况,例如设置视图,并且不应将其视为一种 Three20 实现的单例。每次我试图依靠它来更“聪明”地使用 TTURLMap 时,我发现自己又回到了非共享控制器。
The answer is : no. I.e., init will not be called on an already initialized instance, but a new instance will be allocated and initialized.
This is due to Three20 associating the object to its full URL, which in your case is either "tt://tabbar/string" or "tt://tabbar/somethingelse", so that when querying the
TTURLMap
, no already existing object will be found and a new one will be instantiated. At least, this is true as of Three20 1.0.3. But I guess they have not changed this.In my opinion, the shared controller mechanism is to be used in very specific cases, like for a setting view, and it should not be thought as a sort of Three20-implemented singleton. Each time I tried to rely on this for more "clever" usage of the TTURLMap, I found myself going back to a non shared controller.