TimOliver/TOWebViewController

Can not custom back button

xtreme8210 opened this issue · 5 comments

Hi, i am trying to add a custom button
I have tried these below:

@property (nonatomic,copy)      NSArray *applicationBarButtonItems;
@property (nonatomic, copy)   NSArray *applicationLeftBarButtonItems;
@property (nonatomic,copy)      NSArray *loadCompletedApplicationBarButtonItems;

but I have no lucky, have I done anything wrong?
please help

TOWebViewController *webView = [[TOWebViewController alloc] initWithURL:[NSURL URLWithString:string]];
[nav.navigationBar setBarTintColor:[UIColor redColor]];
[nav.navigationBar setTranslucent:NO];
webView.navigationItem.hidesBackButton = YES;
//=======================================
UIButton *backButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50.0f, 50.0f)];
[backButton setImage:[UIImage imageNamed:@"ic_top_back@2x.png"] forState:UIControlStateNormal];
[backButton setImage:[UIImage imageNamed:@"ic_top_back_h@2x.png"] forState:UIControlStateHighlighted];
[backButton setShowsTouchWhenHighlighted:TRUE];
[backButton addTarget:self action:@selector(backTapped:) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *barBackItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
webView.navigationItem.leftBarButtonItem = barBackItem;

Hi there! Thanks for trying out my library! :)

The class manages the state of all of the bar button items (in both the navigation bar and toolbar) in this method. It's pretty complex, because it's working to account for the sudden transitions that can occur during split screen on iPads, and the size transitions on iPhone 6 Plus. As such, simply setting webVIew.navigationItem.leftBarButtonItem won't work.

As you can see in that code though, if you add your back button to applicationLeftBarButtonItems, it SHOULD work. If it doesn't, please attach a screenshot of what it's doing so we can figure out what we need to do to fix it. :)

Thanks!

Hi Tim,
I have tried applicationLeftBarButtonItems, but still can not add my custom button onto it. Please refer to the attachment. thanks :)
When I press the login button(it's in the storyboard, ) will call

  • (void)showWebViewWithUrl:(NSString *)string navTitle:(NSString *)title navigation:(UINavigationController *)nav;

2016-07-06 10 22 58
2016-07-06 10 15 46

Hmm, that code on line 32 seems strange. At that point, applicationLeftBarButtonItems should be nil in which case that code won't do anything.

Try replacing that line with:

webView.applicationLeftBarButtonItems = @[backBarItem];

Let me know how you go. :)

Hi Tim,
yes, you are right. webView.applicationLeftBarButtonItems is nil.
So I replaced with you code and worked!
thank you very much :)

Woohoo! Glad I could help. You're welcome! :D