dzenbot / DZNWebViewController

A simple web browser for iPhone & iPad with similar features than Safari's
https://www.cocoacontrols.com/controls/dznwebviewcontroller
MIT License
1.06k stars 181 forks source link

Close button #14

Closed jonerickson closed 9 years ago

jonerickson commented 9 years ago

Am I missing something, or how is one suppose to close the view controller once presented?

XAmateur commented 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

joeljfischer commented 9 years ago

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.

jonerickson commented 9 years ago

I have done this however a back button does not appear.

sachinkesiraju commented 9 years ago

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;
abidullah commented 9 years ago

@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

sachinkesiraju commented 9 years ago

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 ios simulator screen shot jan 20 2015 8 52 43 pm

haoyuexing commented 9 years ago

@abidullah i have the same issue. when i close the VC. crash. did u fix it?

abidullah commented 9 years ago

@haoyuexing No it still crash

DreamingInBinary commented 9 years ago

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
haoyuexing commented 9 years ago

@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.