From 7f88abcef3c65c209afcfc2e1c3e52af4bd769c7 Mon Sep 17 00:00:00 2001 From: Mike Seaby Date: Wed, 15 Jun 2011 19:17:51 +0100 Subject: [PATCH] Navigation Bar Left Button now calls back to js & can be now be removed --- Classes/leftButton.h | 8 ++++++-- Classes/leftButton.m | 46 +++++++++++++++++++++----------------------- Classes/screenShot.h | 16 +++++++++++++++ Classes/screenShot.m | 14 ++++++++++++++ 4 files changed, 58 insertions(+), 26 deletions(-) create mode 100644 Classes/screenShot.h create mode 100644 Classes/screenShot.m diff --git a/Classes/leftButton.h b/Classes/leftButton.h index 80c6d7c..ac0a705 100644 --- a/Classes/leftButton.h +++ b/Classes/leftButton.h @@ -6,11 +6,15 @@ // Copyright 2011 Mike Seaby. All rights reserved. // -#import +#import @interface leftButton : NSObject { - + UIWebView *webView; + NSString *currentPage; } +@property (nonatomic, assign) UIWebView *webView; +@property (retain) NSString *currentPage; + @end diff --git a/Classes/leftButton.m b/Classes/leftButton.m index 2cc0940..9167ca4 100644 --- a/Classes/leftButton.m +++ b/Classes/leftButton.m @@ -7,25 +7,19 @@ // #import "leftButton.h" - -UIBarButtonItem *button; -UINavigationController *controller; -UIAlertView *alert; +#import "NKBridge.h" @implementation leftButton +@synthesize webView, currentPage; + - (void)addLeftButton { - controller = [[NSClassFromString(@"NKBridge") sharedInstance] - navigationControllerForPage:@"main.html"]; - - button = [[UIBarButtonItem alloc] - initWithTitle:@"Button" - style:UIBarButtonItemStylePlain - - target:self action:@selector(buttonClicked:)]; - - //button = UIBarButtonSystemItemDone; + UINavigationController *controller = [[NKBridge sharedInstance] navigationControllerForPage:self.currentPage]; + + UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithTitle:@"Button" style:UIBarButtonItemStylePlain target:self action:@selector(buttonClicked:)]; + // UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:@"imagename.png"] style:UIBarButtonItemStylePlain target:self action:@selector(buttonClicked:)]; // in case you want image there + controller.visibleViewController.navigationItem.leftBarButtonItem = button; // ******************************************************************************************************** @@ -62,18 +56,22 @@ - (void)addLeftButton { } -// Called when left button pressed +- (void)removeLeftButton { + UINavigationController *controller = [[NKBridge sharedInstance] navigationControllerForPage:self.currentPage]; + controller.visibleViewController.navigationItem.leftBarButtonItem = nil; +} + +- (void)setNKWebView:(UIWebView*)view { + self.webView = view; +} + +- (void)setNKCurrentPage:(NSString*)page { + self.currentPage = page; +} + - (void) buttonClicked:(id)sender{ - button = (UIBarButtonItem *)sender; - alert = [[UIAlertView alloc] initWithTitle:@"Left Bar Button!" message:@"You Pressed It!" - delegate:self cancelButtonTitle:@"OK!" otherButtonTitles:nil]; - [alert show]; - [alert release]; - - // ******************************************************************************************************** - // TODO: Add method to return button press to javascript - // ******************************************************************************************************** + [self.webView performSelectorOnMainThread:@selector(stringByEvaluatingJavaScriptFromString:) withObject:[NSString stringWithFormat:@"leftButtonClicked()"] waitUntilDone:NO]; } @end diff --git a/Classes/screenShot.h b/Classes/screenShot.h new file mode 100644 index 0000000..d9bdf86 --- /dev/null +++ b/Classes/screenShot.h @@ -0,0 +1,16 @@ +// +// screenShot.h +// ObjC-Mix +// +// Created by Mike Seaby on 30/05/2011. +// Copyright 2011 Mike Seaby. All rights reserved. +// + +#import + + +@interface screenShot : NSObject { + +} + +@end diff --git a/Classes/screenShot.m b/Classes/screenShot.m new file mode 100644 index 0000000..dda2c5f --- /dev/null +++ b/Classes/screenShot.m @@ -0,0 +1,14 @@ +// +// screenShot.m +// ObjC-Mix +// +// Created by Mike Seaby on 30/05/2011. +// Copyright 2011 Mike Seaby. All rights reserved. +// + +#import "screenShot.h" + + +@implementation screenShot + +@end