截屏后,在WebView中更改URL的问题

时间:2016-03-04 20:50:16

标签: ios objective-c

基本上如标题所示,我在WebViewAppDelegate中遇到了一些问题

https://github.com/austin4195/Nucleus-iOS/blob/master/Classes/WebViewAppDelegate.m

第5-48行,但我认为问题在于定义将存储值的项目

谢谢!

1 个答案:

答案 0 :(得分:0)

您的代码存在很多问题:

  • 第36行中有return语句,因此永远不会调用您的代码。
  • screenshotTaken应在application:didFinishLaunchingWithOptions:之外宣布。
  • 您应该使用self.webViewController.theWebView代替webViewController.webView

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
        navigationController = [[UINavigationController alloc] init];
        navigationController.navigationBar.hidden = YES;
        navigationController.toolbar.barStyle = UIBarStyleBlack;
        WebViewController *webViewController = [[WebViewController alloc] init];
        webViewController.urlString = @"http://files.austinapps.org/File%20Site";
        [navigationController pushViewController:webViewController animated:NO];
        [webViewController release];
        [self.window setRootViewController:navigationController];
        [self.window makeKeyAndVisible];
        self.webViewController = webViewController;
        [[NSNotificationCenter defaultCenter] addObserver:self
                                              selector:@selector(screenshotTaken)
                                              name:UIApplicationUserDidTakeScreenshotNotification
                                              object:application];
        return YES;
    }
    
    - (void)screenshotTaken{
        [self.webViewController.theWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://website.com/"]]];
    }