Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1109417
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T02:13:54+00:00 2026-05-17T02:13:54+00:00

Okay, what I currently have is a TabBarController with five tabs. Each of these

  • 0

Okay, what I currently have is a TabBarController with five tabs. Each of these tabs are UINavigationControllers. Each of the Views associated with the tabs link to a XIB file that contains a View with a UIWebView. What I want to happen is when a link is clicked in the UIWebView a new navigation view (with a back button) is pushed onto the stack and the content be filled with the link that was clicked, what actually happens is close but no cigar. It loads the original page I left from, for example: I’m on http://www.example.com and I click a link and the new view loads (with the back button) and just reloads http://www.example.com 🙁

Also, I have a check in the viewDidLoad method to determine which tab is selected which in turns tell what content needs to be present.

Here is my code:

- (void)viewDidLoad {
// Allows webView clicks to be captured.
webView.delegate = self;
// Places statsheet image centered into the top nav bar.
UIImage *image = [UIImage imageNamed: @"header.png"];
UIImageView *imageView = [[UIImageView alloc] initWithImage: image];
self.navigationItem.titleView = imageView;
[imageView release];

// Loads webpage according to the tab selected.
if (self.tabBarController.selectedIndex == 0) {
     [webView loadRequest: [ NSURLRequest requestWithURL: [ NSURL URLWithString: @"http://mobile.example.com" ] ] ];
}
else if (self.tabBarController.selectedIndex == 1) {
    [webView loadRequest: [ NSURLRequest requestWithURL: [ NSURL URLWithString: @"http://mobile.example.com/schedule" ] ] ];    
}
else if (self.tabBarController.selectedIndex == 2) {
    [webView loadRequest: [ NSURLRequest requestWithURL: [ NSURL URLWithString: @"http://mobile.example.com/roster" ] ] ];  
}
else if (self.tabBarController.selectedIndex == 3) {
    [webView loadRequest: [ NSURLRequest requestWithURL: [ NSURL URLWithString: @"http://mobile.example.com/stats" ] ] ];   
}
else if (self.tabBarController.selectedIndex == 4) {
    [webView loadRequest: [ NSURLRequest requestWithURL: [ NSURL URLWithString: @"http://mobile.example.com/about" ] ] ];   
}

// Loads the super class.
[super viewDidLoad];

}

- (BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

NSURL *url = request.URL;
NSString *urlString = url.absoluteString;
NSRange page = [ urlString rangeOfString: @"/?page=" ];
NSRange post = [ urlString rangeOfString: @"/posts/" ];
NSRange notBlog = [ urlString rangeOfString: @"example" ];
// Allow webapge to load if next or prev button is clicked.
if ( page.location != NSNotFound ) {
    return YES;
}
// Pass post link to new view with a back navigation button. 
else if ( post.location != NSNotFound) {
    NavigationViewController *newView = [[NavigationViewController alloc] initWithNibName:@"NavigationView" bundle:nil];
    // ^^^^^^^^^^^^^^^^^^ Here is where the new view is pushed but doesnt load the correct page
    [self.navigationController pushViewController:newView animated:YES];
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc]
    initWithTitle:@"Back"
    style:UIBarButtonItemStyleBordered
    target:nil
    action:nil];
    self.navigationItem.backBarButtonItem = backBarButtonItem;
    [backBarButtonItem release];
    [newView release];
    return NO;
}
// Allow all links that are a part of the five main pages to be loaded.
else if ( notBlog.location != NSNotFound) {
    return YES;
}
//Allows everything else to be loaded into a new view with a back navigation button.
else {
    NavigationViewController *newView = [[NavigationViewController alloc] initWithNibName:@"NavigationView" bundle:nil];
// ^^^^^^^^^^^^^^^^^^ Here is where the new view is pushed but doesnt load the correct page
    [self.navigationController pushViewController:newView animated:YES];
    UIBarButtonItem *backBarButtonItem = [[UIBarButtonItem alloc]
    initWithTitle:@"Back"
    style:UIBarButtonItemStyleBordered
    target:nil
    action:nil];
    self.navigationItem.backBarButtonItem = backBarButtonItem;
    [backBarButtonItem release];
    [newView release];
    return NO;
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T02:13:55+00:00Added an answer on May 17, 2026 at 2:13 am

    In the webView:shouldStartLoadWithRequest you never pass the URL to the “NavigationViewController” instance you create. It can’t work…

    So every time the viewDidLoad is called you call one of your 4 URL depending on the tabBar state.

    Here is what you should do :

    in NavigationViewController :

    • Add an “NSURL *pageURL” attribute
    • Create a good init method :
    -(id)initWithURL:(NSURL *)url
    {
        if ([super initWithNibName:@"NavigationView" bundle:nil])
        {
           _pageURL = [url retain];
        }
        return self;
    }
    

    And in viewDidLoad:

    if (_pageURL == nil) {
    // Loads webpage according to the tab selected.
    if (self.tabBarController.selectedIndex == 0) {
         [webView loadRequest: [ NSURLRequest requestWithURL: [ NSURL URLWithString: @"http://mobile.example.com" ] ] ];
    }
    else if (self.tabBarController.selectedIndex == 1) {
        _pageURL = [ NSURL URLWithString: @"http://mobile.example.com/schedule" ];    
    }
    else if (self.tabBarController.selectedIndex == 2) {
        _pageURL = [ NSURL URLWithString: @"http://mobile.example.com/roster" ];  
    }
    else if (self.tabBarController.selectedIndex == 3) {
        _pageURL = [ NSURL URLWithString: @"http://mobile.example.com/stats" ];   
    }
    else if (self.tabBarController.selectedIndex == 4) {
        _pageURL = [NSURL URLWithString:@"http://mobile.example.com/about" ];   
    }
    }
    
    [webView loadRequest:[NSURLRequest requestWithURL:_pageURL]];
    
    // Loads the super class.
    [super viewDidLoad];
    

    And then initialize correctly your instance in webView:shouldStartLoadWithRequest

    NavigationViewController *newView = [[NavigationViewController alloc] initWithURL:request.URL];
    

    Add to the top

    -(BOOL)webView:(UIWebView*)webView shouldStartLoadWithRequest:(NSURLRequest*)request navigationType:(UIWebViewNavigationType)navigationType {

    NSURL *url = request.URL;

    NSString *urlString = url.absoluteString;

    if ([urlString isEqualToString:_pageURL.absoluteString]){return YES;}

    …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, next PHPExcel question. I have an HTML form that users fill out and
Okay, so I have an issue with an AJAX request. I currently have this
Okay, so I'm using perl to read in a file that contains some general
Okay so I currently have: /(#([\]))/g; I want to be able to check for
Okay so I have encountered a frustrating issue with namespaces. I am currently using
Okay, here's my situation. I have a WPF app that I have created that
Okay this seems like a real noob question. I currently have a simple html
Okay, so I have this array. Currently it pulls multiple payment amounts and dates
Okay, so I'm currently developing an iphone app that I plan to take into
Currently have a solution that was created in VS2003 went to VS2005 and now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.