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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T10:11:00+00:00 2026-05-25T10:11:00+00:00

I want to use a Navigation Controller to help me navigate to the First

  • 0

I want to use a Navigation Controller to help me navigate to the First View & Second View from Main Controller View and eliminating the need to create a Back button so Navigation Controller will handle it for me.

How can I do this? I’m assuming that I’ll put the Navigation Controller in MainWindow.xib.

Please guide me in editing the codes below to fully implement the Navigation Controller from the app.

Complete codes are here (both header and implementation):

MainControllerView.h code

#import <UIKit/UIKit.h>

@class FirstView;

@class SecondView;

@interface MainControllerView : UIViewController {

   IBOutlet UILabel *label;
   IBOutlet UIButton *firstView;
   IBOutlet UIButton *secondView;

    FirstView *firstView1; 
    SecondView *secondView1;

}

@property(nonatomic,retain)  IBOutlet UILabel *label;

@property(nonatomic,retain)  IBOutlet UIButton *firstView;

@property(nonatomic,retain)  IBOutlet UIButton *secondView;


-(IBAction) FirstView:(id)sender;
-(IBAction) SecondView:(id)sender;



@end

MainControllerView.m

#import "MainControllerView.h"
#import "FirstView.h"
#import "SecondView.h"



@implementation MainControllerView

@synthesize label,firstView,secondView;



-(IBAction) FirstView:(id)sender

{

    firstView1 = [[FirstView alloc] 
                   initWithNibName:@"FirstView" 
                   bundle:nil];
    [self.view addSubview:firstView1.view];

}



-(IBAction) SecondView:(id)sender

{
    secondView1 = [[SecondView alloc] 
                  initWithNibName:@"SecondView" 
                  bundle:nil];
    [self.view addSubview:secondView1.view];
}





- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

FirstView.h

#import <UIKit/UIKit.h>

@class MainControllerView;

@interface FirstView : UIViewController {

    IBOutlet UIButton *backButton;
    MainControllerView *mainControllerView;
}

@property(nonatomic,retain)  IBOutlet UIButton *backButton;


@end

FirstView.m

#import "FirstView.h"
#import "MainControllerView.h"


@implementation FirstView

@synthesize backButton;


- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(5,18,100,40);
    [button setImage:[UIImage imageNamed:@"backbutton.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor clearColor];

    [self.view addSubview:button];


    // Do any additional setup after loading the view from its nib.
}


-(IBAction) BackAction:(id)sender

{

    mainControllerView = [[MainControllerView alloc] 
                      initWithNibName:@"MainControllerView"bundle:nil];

    [self.view addSubview:mainControllerView.view];
    [mainControllerView.view release];

}



- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end

SecondView.h

#import <UIKit/UIKit.h>

@class MainControllerView;

@interface SecondView : UIViewController {

    IBOutlet UIButton *backButton;
    MainControllerView *mainControllerView;
}

@property(nonatomic,retain)  IBOutlet UIButton *backButton;

@end

SecondView.m

#import "SecondView.h"
#import "MainControllerView.h"

@implementation SecondView

@synthesize backButton;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)dealloc
{
    [super dealloc];
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];

    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.

    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(5,18,100,40);
    [button setImage:[UIImage imageNamed:@"backbutton.png"] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    button.backgroundColor = [UIColor clearColor];

    [self.view addSubview:button];


    // Do any additional setup after loading the view from its nib.
}


-(IBAction) BackAction:(id)sender

{

    mainControllerView = [[MainControllerView alloc] 
                          initWithNibName:@"MainControllerView"bundle:nil];

    [self.view addSubview:mainControllerView.view];
    [mainControllerView.view release];

}



- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
  • 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-25T10:11:00+00:00Added an answer on May 25, 2026 at 10:11 am

    In your app delegate, just add this code on applicationDidFinishLoading method.

        UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:rootViewController];
    
    [window makeKeyAndVisible];
    [window addSubview:navController.view];
    

    And dont forget to set the title in your initWithNibName method…

    self.title = @"Page Title";
    

    Or you can start your project by choosing the navigation controller template and still dont forget to set the title…

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

Sidebar

Related Questions

I want to use the Publish.GacRemove function to remove an assembly from GAC. However,
I have a query regarding use of navigation Controller and tabBarController together. I will
I'm trying to implement a navigation controller with some hierarchical views. I want to
I want to use a modal view ( UIViewController ) as a normal view,
Below is my stored procedure. I want use stored procedure select all row of
I want to use the mouse scrollwheel in my OpenGL GLUT program to zoom
I want to use Powershell to write some utilities, leveraging our own .NET components
I want to use the functions exposed under the OpenGL extensions. I'm on Windows,
I want to use the MultipleLookupField control in a web page that will run
I want to use the Web Browser control within an mono application, but when

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.