简体   繁体   English

如何将 NSURL 从委托传递给视图控制器

[英]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.

相关问题 如何将带有委托的数据从页脚单元格传递到视图控制器? - How to pass data with delegate from footer cell to view controller? 如何将变量从View Controller传递到App Delegate - How to pass a variable from View Controller to App Delegate 如何使用委托将数据从一个视图控制器传递到另一个视图控制器? - how to use delegate to pass data to from one View Controller to another? 如何使用委托将数据从多个视图控制器传递回根视图控制器? IOS 7 - How to pass data back from multiple view controllers to root view controller using delegate? Ios 7 如何使用委托将消息从一个视图控制器传递到另一个使用委托的视图控制器? - How to pass message using delegates from one view controller to another using delegate? 如何使用委托将变量传递给另一个视图控制器 - how to pass a variable to another view controller using delegate 将scrollview委托传递给子视图控制器 - Pass scrollview delegate to child view controller 如何将NSURL从一个类传递到另一个类? - How to pass NSURL from one class to another? 如何从应用程序委托访问字符串(在视图控制器中) - How to access string (which is in view controller) from the app delegate 如何在应用程序委托中使用视图控制器中的功能? - How to use a function from the view controller in the app delegate?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM