简体   繁体   English

通过TTURLAction在视图控制器中调用方法?

[英]Calling a method in a View Controller via a TTURLAction?

I've created a Download Manager which is pretty much a TTTableViewController and it's accompanying DataModel is a pretty much an ASINetworkQueue. 我已经创建了一个下载管理器,它几乎是一个TTTableViewController,它附带的DataModel几乎是一个ASINetworkQueue。

So, when I've created a function in my view controller that in turns call my [dataModel addDownloadWithNameAndUrl: url:] and I get a new download added to the NetworkQueue, which starts, and is being displayed on the TTTableViewController and updates progress bars and the rest. 因此,当我在视图控制器中创建了一个函数后,依次调用我的[dataModel addDownloadWithNameAndUrl:url:]并将新下载添加到NetworkQueue中,该下载开始,并显示在TTTableViewController上并更新进度条其余的。

I've also mapped the DownloadManagerViewController class to a URL, and I can use the TTNavigator to open the download manager. 我还将DownloadManagerViewController类映射到URL,并且可以使用TTNavigator打开下载管理器。

Now for my question. 现在我的问题。 Is there a way I can call the url to execute the requested function without switching to the View Controller? 有没有一种方法可以调用url来执行请求的功能,而无需切换到View Controller? How could I accomplish some 我怎么能完成一些

Have you tried looking in the samples/TTNavigatorDemo project? 您是否尝试过查看示例/ TTNavigatorDemo项目? It has a lot of URL mapping examples. 它有很多URL映射示例。

Try using the [map from:<#(NSString *)#> toObject:<#(id)#> selector:<#(SEL)#>] function, such as: 尝试使用[map from:<#(NSString *)#> toObject:<#(id)#> selector:<#(SEL)#>]函数,例如:

[map from:@"tt://order/send" toObject:_controller selector:@selector(sendOrder)];

If I find myself needing the controller as an object, I initialize the object in the app delegate instead, such as: 如果我发现需要控制器作为对象,则可以在应用程序委托中初始化该对象,例如:

 _playerController = [[PlayerController alloc] init];
 [map from:@"radio://player/(initWithStation:)" toViewController:_playerController transition:UIViewAnimationTransitionNone];

Well as a matter of fact it appears to be rather simple although it took me a while to figure it out. 事实上,这看起来很简单,尽管花了我一段时间才弄清楚。

Thee20 Navigator has method: Thee20 Navigator具有以下方法:

- (id) viewControllerForURL: (NSString *) url;

By using that, throughout the application you can get an instance of your view controller that you have assigned to the url. 通过使用它,可以在整个应用程序中获取分配给该URL的视图控制器的实例。 However the trick is that if you have set the url as a 但是,诀窍在于,如果您将网址设置为

[map @"url" toViewController: <class>];

each time you get a new instance of the View Controller. 每次您获得View Controller 的新实例时。

In my case however, I wanted to use the already instantiated view controller so I need to setup the url as a sharedViewController . 但是,就我而言,我想使用已经实例化的视图控制器,因此需要将URL设置为sharedViewController

So I've added a new method to my view controller which now I can call without switching the UI to it. 因此,我在视图控制器中添加了一个新方法,现在无需调用UI即可调用该方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM