i want navigate to another file in webview.

i want to call objective c file from javascript.

- (void)viewDidLoad
{
webview.delegate = self;

myButton.enabled = NO;

NSString *path=[[NSBundle mainBundle]pathForResource:@"1" ofType:@"html" inDirectory:@"files"];
NSURL *url=[NSURL fileURLWithPath:path];
NSURLRequest *request=[NSURLRequest requestWithURL:url];
[webview loadRequest:request];} 

i am using this code to call my html page successfully and i use the below code to call shouldStartLoadWithRequest method in objective c.

<a href="didTap://button1"><img src="cercle24px.png" /></a>

now i went to call new TestViewController.m file how to i call this file, i used the below code.its print the nslog correctly and give alert box also.but doesn't navigate to next file.please help me if any one know.i am waiting for your valuable reply please.

    - (BOOL)webView:(UIWebView*)webview shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType
 {  
  NSLog(@"what");
   UIAlertView *tstAlert = [[UIAlertView alloc] initWithTitle:@"" message:@"Allowed only alphabets and numeric" delegate:self  cancelButtonTitle:nil otherButtonTitles:@"Ok",nil];
[tstAlert show];
NSString *absoluteUrl = [[request URL] absoluteString];
NSLog(@"absolute%@",absoluteUrl);
if ([absoluteUrl isEqualToString:@"didtap://button1"]) {
    NSLog(@"yes");

  TestViewController *testview=[[TestViewController alloc]initWithNibName:@"TestViewController" bundle:nil]; 
  [self.navigationController pushViewController:testview animated:YES];


        return NO;


  }
   NSLog(@"no");
  return YES;

  }

Answers


Alright, I copy & tested your code, it works well, maybe somewhere else did wrong... Create a new "Empty Template" Xcode project with ARC enabled, paste below into AppDelegat.m:

//
//  AppDelegate.m
//  WebTest
//
//  Created by Elf Sundae on 8/5/13.
//  Copyright (c) 2013 www.0x123.com. All rights reserved.
//

#import "AppDelegate.h"

@interface SampleViewController : UITableViewController
@end

@implementation SampleViewController
- (void)viewDidLoad
{
        [super viewDidLoad];
        self.title = @"Sample Controller";
}
@end

#pragma mark - 
@interface WebViewController : UIViewController <UIWebViewDelegate>
@end

@implementation WebViewController
- (void)viewDidLoad
{
        [super viewDidLoad];
        UIWebView *web = [[UIWebView alloc] initWithFrame:self.view.bounds];
        web.delegate = self;
        [self.view addSubview:web];
        [web loadHTMLString:@"<a href='didTap://button1'><img src='cercle24px.png' /></a>" baseURL:nil];
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request
 navigationType:(UIWebViewNavigationType)navigationType
{
        UIAlertView *alert = [[UIAlertView alloc]
                              initWithTitle:nil message:@"alert message" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
        [alert show];

        NSString *urlString = request.URL.absoluteString;
        if ([urlString caseInsensitiveCompare:@"didtap://button1"] == NSOrderedSame) {

#define __use_method   3 // it could be: 1/2/3

#if (__use_method == 1)
                SampleViewController *controller = [[SampleViewController alloc] init];
                [self.navigationController pushViewController:controller animated:YES];
#elif (__use_method == 2)

                /* method 2 */
                SampleViewController *controller = [[SampleViewController alloc] init];
                [self.navigationController performSelector:@selector(pushViewController:animated:)
                                                withObject:controller
                                                withObject:@(YES)];
#elif (__use_method == 3)
                /* method 3 */
                __unsafe_unretained __typeof(self) _self = self;
                double delayInSeconds = 0.01;
                dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(delayInSeconds * NSEC_PER_SEC));
                dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
                        SampleViewController *controller = [[SampleViewController alloc] init];
                        [_self.navigationController pushViewController:controller animated:YES];
                });
#endif

                return NO;
        }
        return YES;
}

@end

#pragma mark - 
@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        [self.window makeKeyAndVisible];
        self.window.rootViewController = [[UINavigationController alloc] initWithRootViewController:
                                          [WebViewController new]];
        return YES;
}

@end

Need Your Help

How do I call a Method in C#?

c#

I'm trying to learn how methods work in C# (Also using the XNA Framework).

JSP include other jsp page

java jsp hashmap

for example i made three jsp file like this

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.