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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:41:56+00:00 2026-05-23T08:41:56+00:00

I have programmatically created a second view controller (MySecondViewController) which was all done and

  • 0

I have programmatically created a second view controller (MySecondViewController) which was all done and hooked up without using the visual object editor.

My problem is that when I run the app, only the original view controller (HelloWorldViewController) comes up; the second view controller does not show up. When I click on the view for HelloWorldViewController, nothing comes up.

Can you tell me what’s wrong?

windowBasedAppAppDelegate.h

#import <UIKit/UIKit.h>

//-- Add a forward reference to the HelloWorldViewController class --

@class HelloWorldViewController;

@interface windowBasedAppAppDelegate : NSObject <UIApplicationDelegate> {
    //-- create an instance of the view controller--
    HelloWorldViewController *viewController;

}

@property (nonatomic, retain) IBOutlet UIWindow *window;

//--Expose the view controller as a property--
@property (nonatomic, retain) IBOutlet HelloWorldViewController *viewController;

@end

windowBasedAppAppDelegate.m

#import "windowBasedAppAppDelegate.h"
#import "HelloWorldViewController.h"
#import "MySecondViewController.h"

@implementation windowBasedAppAppDelegate


@synthesize window;
@synthesize viewController;

//-- a second view controller object--
MySecondViewController *mySecondViewController;

- (BOOL)application:(UIApplication *)application     didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.
    //-- add the new view to the current window--
    //-- instantiate the second view controller --
    mySecondViewController = [[MySecondViewController alloc]
                          initWithNibName:nil
                          bundle:nil];

   // -- add the view from the second controller --
   //[window addSubview:mySecondViewController.view];

   [window addSubview:viewController.view];
   [self.window makeKeyAndVisible];
   return YES;
}

- (void)dealloc
{
    [MySecondViewController release];
    [viewController release];
    [window release];
    [super dealloc];
}

@end

MySecondViewController.h

#import <UIKit/UIKit.h>


@interface MySecondViewController : UIViewController {
    //-- create two outlets, label and button --
    UILabel *label;
    UIButton *button;

}

//-- expose the outlets as properties --

@property (nonatomic, retain) UILabel *label;
@property (nonatomic, retain) UIButton *button;

// -- declaring the IBAction ---
- (IBAction) buttonClicked: (id)sender;

@end

MySecondViewController.h

#import "MySecondViewController.h"


@implementation MySecondViewController

@synthesize label, button;

- (IBAction) buttonClicked: (id)sender {
    UIAlertView *alert =
    [[UIAlertView alloc] initWithTitle:@"Action Invoked!" message:@"Button clicked"     delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
    [alert show];
    [alert release];
}

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

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

HelloWorldViewController.h

#import <UIKit/UIKit.h>


@interface HelloWorldViewController : UIViewController {

}

@end

HelloWorldViewController.m

import "HelloWorldViewController.h"

@implementation HelloWorldViewController

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

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

Added code from MySecondViewController.m

//-- add the views to the view window --
    [self.view addSubview:label];
    [self.view addSubview:button];
    [view exchangeSubviewAtIndex:1 withSubviewAtIndex:0];
    self.view = view;
    [super viewDidLoad];
  • 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-23T08:41:56+00:00Added an answer on May 23, 2026 at 8:41 am

    Since the view is being initialized and that it has a proper frame, the problem could be this sequence of code,

    [window addSubview:mySecondViewController.view];
    [window addSubview:viewController.view];
    

    As the viewController‘s view will have the same frame, it will be added over mySecondViewController‘s view. So you will have to remove the second line for the view to show up.

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

Sidebar

Related Questions

I need to create a Firebird Database programmatically using DBExpress. I have done this
I have a navigation controller created programmatically to handle the switch between the views
I've got a custom page I created programmatically using hook_menu. I can have it
I have a C code base and need to programmatically identify all of the
I have a tableLayout that is created programmatically, about 23 items are added to
I am having some problems with uitabbaritem. I have created uitabbaritem programmatically. And what
How can I programmatically determine if I have access to a server (TCP) with
I have to lock user accounts in Active Directory programmatically in C#. Unfortunately it
I have a map of a building and I'd like to programmatically highlight specific
I have a carbon C++ application and I would like to programmatically do the

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.