[英]How to pass NSURL to view controller from delegate
So my application opens a file format.所以我的应用程序打开了一种文件格式。 Since the app is running it uses applicationWillEnterForeground to call application:openURL:sourceApplication:annotation:.
由于应用程序正在运行,它使用 applicationWillEnterForeground 调用 application:openURL:sourceApplication:annotation:。 Once I have my NSURL in my delegate my previous view opens and I have done anything with the NSURL.
一旦我在我的委托中有我的 NSURL,我之前的视图就会打开,我已经对 NSURL 做了任何事情。
My app of course is using a storyboard so I just can't call the XIB like most tutorials have you do.我的应用程序当然使用的是故事板,所以我不能像大多数教程那样调用 XIB。 So my question how do I get that file to view controller to open and progress it?
所以我的问题是如何让该文件查看控制器以打开和处理它?
You can create property in your AppDelegate.h file to hold the NSURL:您可以在 AppDelegate.h 文件中创建属性来保存 NSURL:
@property (nonatomic, string) NSURL *myURL;
And in而在
application:openURL:sourceApplication:annotation:
应用程序:openURL:sourceApplication:annotation:
save the url to new property:将 url 保存到新属性:
self.myUrl = url;
After that you can access the url from every single view controller in your app.之后,您可以从应用程序中的每个视图控制器访问该 url。 Passing url from delegate is not good solution because when the
从委托传递 url 不是一个好的解决方案,因为当
application:openURL:sourceApplication:annotation:
应用程序:openURL:sourceApplication:annotation:
is called your view controller can be nil.被称为您的视图控制器可以为零。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.