IOS 从 AppDelegate.h 推送 ViewController

发布于 2024-12-27 10:49:33 字数 894 浏览 2 评论 0原文

我正在使用包含各种 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

别忘他 2025-01-03 10:49:33

您不应该实现 application:handleOpenURL: 方法。它不仅已被弃用,而且它的作用是要求应用程序委托允许在浏览器中打开 URL。

您想要做的是在 DetailViewController 中实现 UIWebViewControllerDelegate 协议。具体来说,您应该实现 – webView:shouldStartLoadWithRequest:navigationType: 方法。其中:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
   [ImageViewController *imageViewController =[[ImageViewController alloc]init];
   imageViewController.imageString = param;
   [root.navigationController pushViewController:imageViewController animated:YES];

   return YES;
} 

在此方法中,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 the DetailViewController. Specifically you should implement the – webView:shouldStartLoadWithRequest:navigationType: method. In it:

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
   [ImageViewController *imageViewController =[[ImageViewController alloc]init];
   imageViewController.imageString = param;
   [root.navigationController pushViewController:imageViewController animated:YES];

   return YES;
} 

In this method, the UIWebView instance asks its delegate for permission to open an url.

Hope it helps

小嗷兮 2025-01-03 10:49:33

请注意,此方法已被弃用:
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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文