Skip to content

Commit

Permalink
Navigation Bar Left Button now calls back to js & can be now be removed
Browse files Browse the repository at this point in the history
  • Loading branch information
pixelspring committed Jun 15, 2011
1 parent 23d80ef commit 7f88abc
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 26 deletions.
8 changes: 6 additions & 2 deletions Classes/leftButton.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@
// Copyright 2011 Mike Seaby. All rights reserved.
//

#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>


@interface leftButton : NSObject {

UIWebView *webView;
NSString *currentPage;
}

@property (nonatomic, assign) UIWebView *webView;
@property (retain) NSString *currentPage;

@end
46 changes: 22 additions & 24 deletions Classes/leftButton.m
Original file line number Diff line number Diff line change
Expand Up @@ -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;

// ********************************************************************************************************
Expand Down Expand Up @@ -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
16 changes: 16 additions & 0 deletions Classes/screenShot.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// screenShot.h
// ObjC-Mix
//
// Created by Mike Seaby on 30/05/2011.
// Copyright 2011 Mike Seaby. All rights reserved.
//

#import <Foundation/Foundation.h>


@interface screenShot : NSObject {

}

@end
14 changes: 14 additions & 0 deletions Classes/screenShot.m
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 7f88abc

Please sign in to comment.