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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T23:53:12+00:00 2026-05-26T23:53:12+00:00

I have searched far and wide for an answer to this question and would

  • 0

I have searched far and wide for an answer to this question and would be really grateful of some help. I have removed the rest of my application to keep the question simple.

My root view is simply a blank view with one button. It has been initialised with a UINaviagationController. All I want to do is to have the button push a new view onto the stack when pressed. At the moment, the button does nothing when pushed, here is my code.

#import <UIKit/UIKit.h>

@class ViewController;

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (strong, nonatomic) ViewController *viewController;

@end


@implementation AppDelegate

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;

    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:self.viewController];  

    [self.window addSubview:navigationController.view];  

    [self.window makeKeyAndVisible];  

    return YES;
}

Then in my first view controller:

#import "ViewController.h"

@implementation ViewController

-(IBAction)switchView:(id)sender
{
View2 *v2 = [[View2 alloc] initWithNibName:@"View2" bundle:nil];

[self.navigationController pushViewController:v2 animated:YES];

}

The -(IBAction) is configured properly, but still nothing, any ideas?

EDIT::

I have found a workaround to this.

It seems that when trying to access the NavigationController from the root view, using [self.navigationController…. ] will not send the message to the instance of navigationController (no idea why!).

I got it working by adding an ivar to ViewController of type UINavigationController, and then setting the ivar from AppDelegate after initializing ViewController, like such:

    self.viewController = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
    self.window.rootViewController = self.viewController;


  //The UINavigationController declared int AppDelegate.h
    navController = [[UINavigationController alloc] initWithRootViewController:self.viewController];  

    [self.window addSubview:navController.view];

  //Set the ivar on ViewController (navCon) to the UINavigationController we just 
  //initialized 
    self.viewController.navCon = navController; 

Now when sending the message to the NavigationController in ViewController.m, I use the lines

View2 *v2 = [[View2 alloc] initWithNibName:@"View2" bundle:nil];

[navCon pushViewController:v2 animated:YES];

This does work, but I feel as though this is not the way it should be done, any thoughts?

  • 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-26T23:53:13+00:00Added an answer on May 26, 2026 at 11:53 pm

    Your code in application: didFinishLaunchingWithOptions: is pretty messed up. You must make the navigation controller your window’s rootViewController, not the nav controller’s root view controller. Then, the line [self.window addSubview:navigationController.view]; is superfluous and should be removed.

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

Sidebar

Related Questions

I have searched far and wide on this one, but haven't really found a
this is a PHP related question. I have searched far and wide for a
I have searched on stack but no question or answer answers this question directly
I have searched the internet far and wide and seen many questions like this,
I have searched far and wide on the Internet but have not found anything
I have searched a bit on google, but didn't really found an answer to
I've searched pretty far and wide for the past several days and have little
I have searched the web for this but so far got nowhere. I have
I've searched far and wide for suggestions and solutions to this problem, but I'm
I have searched (probed ,even) for an answer to this but haven't come up

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.