Closed jonerickson closed 9 years ago
I have the same issue.I present this controller and I add a dismiss barbutton just like others ,then when I dismiss it ,the issue appears .
put "_webView.scrollView.delegate = nil;" to dealloc method .It may work
But it still has warning in console : <CATransformLayer: 0x7ca8e0e0> - changing property opaque in transform-only layer, will have no effect ;
To fix it ,try this :
http://stackoverflow.com/questions/12341463/using-catransformlayer-warning-changing-property-opaque-in-transform-only-layer
I believe it's meant to be used on a UINavigationController, which means it would receive a back button like any other View Controller would.
I have done this however a back button does not appear.
I found a way to add a back button to the web controller. You'll need to add the bar button item to DZNWebViewController's navigation item rather than to the navigation item on the navigation controller.
DZNWebViewController *controller = [[DZNWebViewController alloc] initWithURL:[NSURL URLWithString:@"https://google.com/"]];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithTitle:@"CLOSE" style:UIBarButtonItemStylePlain target:self action:@selector(closeButtonWithWebView:)];
controller.navigationItem.rightBarButtonItem = closeButton;
@sachinkesiraju i tried the same but when i select close button the view controller exits but crashes , any idea how u did it , can u share that code
Hmm, it works just fine for me. Here's the code I'm using.
@property (strong, nonatomic) UINavigationController *navController; (in the @interface)
- (void) close
{
NSLog(@"Closing view");
[_navController dismissViewControllerAnimated:YES completion:nil];
}
- (void) openWebsiteWithURL: (NSString *) URL
{
DZNWebViewController *webViewController = [[DZNWebViewController alloc] initWithURL:[NSURL URLWithString:URL]];
_navController = [[UINavigationController alloc] initWithRootViewController:webViewController];
webViewController.supportedWebActions = DZNWebActionAll;
webViewController.supportedWebNavigationTools = DZNWebNavigationToolAll;
webViewController.showLoadingProgress = YES;
webViewController.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"Close" style:UIBarButtonItemStylePlain target:self action:@selector(close)];
[self presentViewController:_navController animated:YES completion:nil];
}
And this is what it looks like
@abidullah i have the same issue. when i close the VC. crash. did u fix it?
@haoyuexing No it still crash
You can fix this by using a static context on your wrapper class to open a URL. Here is mine:
//
// WebHelper.h
// HaloTimer
//
// Created by Jordan Morgan on 2/24/15.
// Copyright (c) 2015 Jordan Morgan. All rights reserved.
//
#import <Foundation/Foundation.h>
@class DZNWebViewController;
@interface WebHelper : NSObject
+ (void)openURL:(NSURL *)url fromViewController:(UIViewController *)sender;
@end
And the implementation:
//
// WebHelper.m
// HaloTimer
//
// Created by Jordan Morgan on 2/24/15.
// Copyright (c) 2015 Jordan Morgan. All rights reserved.
//
#import "WebHelper.h"
#import "DZNWebViewController.h"
static UINavigationController *navVC = nil;
static DZNWebViewController *webVC = nil;
@implementation WebHelper
+ (void)openURL:(NSURL *)url fromViewController:(UIViewController *)sender
{
if (!navVC && !webVC)
{
webVC = [[DZNWebViewController alloc] initWithURL:url];
navVC = [[UINavigationController alloc] initWithRootViewController:webVC];
}
else
{
webVC.URL = url;
}
webVC.supportedWebNavigationTools = DZNWebNavigationToolAll;
webVC.supportedWebActions = DZNWebActionAll;
webVC.showLoadingProgress = YES;
webVC.allowHistory = YES;
webVC.hideBarsWithGestures = YES;
webVC.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(close)];
[sender presentViewController:navVC animated:YES completion:NULL];
}
+ (void)close
{
[navVC dismissViewControllerAnimated:YES completion:nil];
}
@end
@DreamingInBinary It's worked. but another issue here. open first page -> close -> open second page. now "back button" can be click. It will back to the first page. i think the logic is wrong. how can i open this VC without the previous record?! thanks.
Am I missing something, or how is one suppose to close the view controller once presented?