IOS 从 AppDelegate.h 推送 ViewController
我正在使用包含各种 ViewController 和 TableViewController 的 StoryBoard,特别是 ImageViewController ,它仅显示图像。我的 DetailViewController 包含一个 UIWebView,这里有一个链接,按下时我试图加载我的 ImageViewController。
链接是
View Image
`In AppDelegate.m 我通过处理handleOpenURL 获取文件名值。
我是 IOS 新手,正在努力如何从 AppDelegate.m 中的 handleOpenURL 方法加载 ImageViewController 。
我的代码是:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSString *param = [keyValueParm objectForKey:@"filename"];
NSLog(@"Param: %@",param);
ImageViewController *imageViewController =[[ImageViewController alloc]init];
imageViewController.imageString = param;
UIViewController *root = self.window.rootViewController;
[root.navigationController pushViewController:imageViewController animated:YES];
return true;
}
目前没有任何反应。
I'm using a StoryBoard which contains various ViewControllers and a TableViewController, one in particular is ImageViewController which just displays an image. My DetailViewController contains a UIWebView, here I have a link, when pressed I am trying to load a my ImageViewController.
The link is
View Image
`
In AppDelegate.m I get the filename value by handling handleOpenURL.
I'm new to IOS and struggling how to load my ImageViewController from the handleOpenURL method in AppDelegate.m.
My code is:
- (BOOL)application:(UIApplication *)application handleOpenURL:(NSURL *)url
{
NSString *param = [keyValueParm objectForKey:@"filename"];
NSLog(@"Param: %@",param);
ImageViewController *imageViewController =[[ImageViewController alloc]init];
imageViewController.imageString = param;
UIViewController *root = self.window.rootViewController;
[root.navigationController pushViewController:imageViewController animated:YES];
return true;
}
At present nothing happens.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不应该实现
application:handleOpenURL:
方法。它不仅已被弃用,而且它的作用是要求应用程序委托允许在浏览器中打开 URL。您想要做的是在
DetailViewController
中实现UIWebViewControllerDelegate
协议。具体来说,您应该实现– webView:shouldStartLoadWithRequest:navigationType:
方法。其中:在此方法中,
UIWebView
实例向其委托请求打开 URL 的权限。希望有帮助
You should't implement the
application:handleOpenURL:
method. Not only it is deprecated, but what it does is ask the application delegate to allow opening an URL in the browser.What you want to do instead is implement the
UIWebViewControllerDelegate
protocol in theDetailViewController
. Specifically you should implement the– webView:shouldStartLoadWithRequest:navigationType:
method. In it:In this method, the
UIWebView
instance asks its delegate for permission to open an url.Hope it helps
请注意,此方法已被弃用:
http://developer.apple.com/ library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html
另外,请确保您的应用程序委托application:didFinishLaunchingWithOptions: 方法返回 YES 或者如果您的委托实现了 applicationDidFinishLaunching:,您的代码将不会被调用:
如果委托从 application:didFinishLaunchingWithOptions: 方法的实现中返回 NO,则不会调用此方法。如果您的应用程序实现了 applicationDidFinishLaunching: 方法而不是 application:didFinishLaunchingWithOptions:,则在应用程序初始化后将调用此方法来打开指定的 URL。
Take care, this method is depecrated :
http://developer.apple.com/library/ios/#documentation/uikit/reference/UIApplicationDelegate_Protocol/Reference/Reference.html
Also, be sure to have your app delegate application:didFinishLaunchingWithOptions: method to return YES or if your delegate implements the applicationDidFinishLaunching:, your code won't get called :
This method is not called if the delegate returns NO from its implementation of the application:didFinishLaunchingWithOptions: method. if your application implements the applicationDidFinishLaunching: method instead of application:didFinishLaunchingWithOptions:, this method is called to open the specified URL after the application has been initialized.