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

  • Home
  • SEARCH
  • 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 1086639
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:50:18+00:00 2026-05-16T22:50:18+00:00

I want to use a modal view ( UIViewController ) as a normal view,

  • 0

I want to use a modal view (UIViewController) as a “normal” view, which can be pushed on the navigation controller stack. Normally, a modal view is presented like this:

LoginViewController *myView = [[MyViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myView];
[self.navigationController presentModalViewController:navController animated:YES];
[myView release];
myView = nil;
[navController release];
navController = nil;

But I want to do something like this:

[[self navigationController] pushViewController:myView animated:YES];

The problem is that my modal view has a right and a left button. So I would have to check how the view is loaded and present the buttons in another way. The idea behind this is to have the back button. So I can use the same modal view a few times.

Edit:

@petert:

Now I followed your example. My issue is that I’m using a UINavigationBar for the modal view. To get this UINavigationBar I create a navigation controller. I’m using the navigation bar because I have my buttons in it. So checking if parentViewController is of type UINavigationController does not work for me. I’m always getting a modal view. Here is how I do it:

// load modal view
MyViewController *myView = [[MyViewController alloc] init];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:myView];
[[self navigationController] presentModalViewController:navController animated:YES];
[navController release];
navController = nil;
[myView release];
myView = nil;


// load as normal view
MyViewController *myView = [[MyViewController alloc] init];
[[self navigationController] pushViewController:myView animated:YES];
  • 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-16T22:50:19+00:00Added an answer on May 16, 2026 at 10:50 pm

    Good tips in this StackOverflow answer.

    I prefer to use UIViewController‘s property:

    @property(nonatomic, readonly) UIViewController *parentViewController
    

    in a view controller’s subclass:

    Look at the value of the controller’s parentViewController property. If it’s an instance of UINavigationController, then you’re in the navigation stack. If you’re being displayed modally, it’ll be an instance of your last view controller.

    So in -viewDidLoad for example:

    - (void)viewDidLoad
    {
       if ([self.parentViewController isKindOfClass:[UINavigationController class]])
         {
            // navigation controller
            self.title = @"...";
         }
       else
         {
            // modal
            self.title = @"Modal";
    
            // add cancel and done buttons now...
         }
    }
    

    Or, a pretty simple solution would be to customize your init method to your MyViewController class to encode your intent for the view controller.

    Add the following to the MyViewController header:

    @interface MyViewController : UIViewController
    {
      BOOL modal;
    }
    
    - (id)initForModal:(BOOL)isModal;
    
    @end
    

    Now in the implementation file:

    @interface MyViewController ()
    @property (nonatomic) BOOL modal;
    @end
    
    @implementation MyViewController
    
    @synthesize modal;
    
    - (id)initForModal:(BOOL)isModal;
    {
      if (self = [super initWithNibName:@"MyViewController" bundle:nil])
        {
          self.modal = isModal;
        }
    
      return self;
    }
    
    - (void)viewDidLoad
    {
      [super viewDidLoad];
    
      if (self.modal)
        {
          // add cancel and done buttons …
        }
      else
        {
          // assuming we're presented from a navigation view …
        }
    }
    

    Now to use this modally:

    // load modal view
    MyViewController *myView = [[MyViewController alloc] initForModal:YES];
    

    Or not modally:

    // load as normal view
    MyViewController *myView = [[MyViewController alloc] initForModal:NO];
    

    I’m assuming you’re creating the view controller(s) from NIBs, but as always see the View Controller Progamming Guide for iOS and especially the section titled “Defining a Custom View Controller Class”.

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

Sidebar

Related Questions

No related questions found

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.