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 4064874
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T15:54:43+00:00 2026-05-20T15:54:43+00:00

I have an application with UITabBarController, where the first tab contains a ViewController of

  • 0

I have an application with UITabBarController, where the first tab contains a ViewController of an HomePage. What I have to do, is to switch between the tabs (this is pretty simple: [[self tabBarController] setSelectedIndex:index]), AND to navigate through outlets of the selectedTab from the “HomePage”.

Just to explain myself: TabElement1—>TabElementX—->UISegmentedController:segmentY

The problem is that the UISegmentedController is nil because it is not initialized yet (at least the first time I do the operation). How should I fix this problem? The tab elements are loaded with nibs.

EDIT– Here’s some code:

@implementation HomeViewController    // Tab Indexed 0
// ...
- (void)playVideoPreview {
NSArray *array;
array = [[self tabBarController] viewControllers];
    // This is a test where I programmatically select the tab AND the switch.
[[[array objectAtIndex:2] switches] setSelectedSegmentIndex:1];
[[self tabBarController] setViewControllers:array];
}
@end

@implementation TGWebViewController    // Tab Indexed 2
// ...
@synthesize switches;    // In .h file: @property (nonatomic, retain) IBOutlet UISegmentedControl switches; Properly linked within the XIB.
- (IBAction)switchHasChangedValue {
    // Foo operations.
}

Now the first time I fire playVideoPreview I manage to get Into the Tab Indexed 2, TGWebViewController, but switches doesn’t exists yet, so I find myself with the segmentedControl named “switches” with the first segment selected. If I get back to HomeViewController, then I fire again playVideoPreview, I get the correct behaviour.

  • 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-20T15:54:44+00:00Added an answer on May 20, 2026 at 3:54 pm

    I’ve fixed the problem using the delegates and a boolean. Now, when the loading of the ViewController at index 2 of TabBar is finished, it sends a message to its delegate which tells what segment has to be selected.

    EDIT Here’s the code (hope it helps):

    // Method in the first View that asks to tab the tab bar to launch the other
    // view controller
    
    - (void)playVideoPreview {
    NSArray *array;
    
    array = [[self tabBarController] viewControllers];
        if ( ![[array objectAtIndex:2] catSwitch] ) {
           [[array objectAtIndex:2] setDelegate:self];
           [[array objectAtIndex:2] setHasBeenLaunchedByDelegate:YES];
        } else {
           [self selectTab];
        }
        [[self tabBarController] setViewControllers:array];
        [[self tabBarController] setSelectedIndex:2];
    }
    
    // Now the operations performed by the second View Controller
    - (void)somewhereInYourCode {
        if ( hasBeenLaunchedByDelegate ) {
            [[self delegate] selectTab];
        }
    }
    
    // In the First View Controller this is the delegate method, 
    // launched from the Second View Controller
    - (void)selectTab {
        NSArray *array;
    
    array = [[self tabBarController] viewControllers];
        [[[array objectAtIndex:2] catSwitch] setSelectedSegmentIndex:[[bannerPreview pageControl] currentPage]];
    }
    
    // Some declaration
    @protocol SecondViewControllerDelegate;
    class SecondViewController : ViewController {
        id<TGWebViewControllerDelegate> delegate;
    }
    @end
    
    @protocol SecondViewControllerDelegate 
        - (void)selectTab;
    @end
    
    // Meanwhile in the first view
    class FirstViewController : ViewController <SecondViewControllerDelegate> {
    // ...
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using a UITabBarController in my application and when I switch between tabs
My application uses UITabBarController with 4 tabs. Each tab will have a UIWebView along
I have a UITabBarController. One of the tab shows application bookmarks, these bookmarks are
I have an application that has a UITabBarController with two tabs, each having its
I have an application that uses a UITabBarController, and inside each tab I have
I have an iphone application that crashes when I switch between two of the
I am having trouble with my UITabBarController. In my application I have 4 tabs,
I have application where i have two view controllers my first view and second
I have application with needs to have access to some sensitive data(in this case
I have created tab bar programmatically in the view controller. In my application, Initially

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.