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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T04:18:41+00:00 2026-06-09T04:18:41+00:00

New to iOS dev. Kindly correct me if i am wrong? I have a

  • 0

New to iOS dev. Kindly correct me if i am wrong?

I have a UIWindow, and rootviewcontroller is :

@interface ViewController : UIViewController
{
IBOutlet UIButton *but;
}

@property (nonatomic, strong) UIButton  *but;
-(IBAction) butButtonPressed;

@end

ie: If i make this Viewcontroller as a root view controller, the UIView that is available in the ViewController is displayed. Understood.

I have created a new class inherited from UIViewController, and along with its .xib file.

So xib file name is : view1.xib,

My Objective is to display this view when the button is pressed.

Now i have created a button and button press invokes butButtonPressed. Inside of butButtonPressed, i did the following.

  myViewController *vcontroler = [[ViewController alloc] initWithNibName:@"view1" bundle:nil];
    [self.view.window addSubview:vcontroler.view];

Application crashes. What am i doing wrong ? Kindly point out.

  • 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-06-09T04:18:42+00:00Added an answer on June 9, 2026 at 4:18 am

    This…

    [self.view.window addSubview:vcontroler.view];
    

    …is a really bad strategy (and I seriously wish I knew where people are finding it as a way of showing views). If you create a view controller, you should use it rather than just treating it as a temporary container that you can rip views out of.

    If you want vcontroler to look like a child of your first controller (and you have a UINavigationController), use pushViewController:animated:. Otherwise you can show it as modal with presentModalViewController:animated:.

    If you only want to add a view to the existing display, put the view in ViewController‘s hierarchy and show/hide it.

    If you absolutely must have it as a sub-controller of ViewController then you need to keep a reference to it and manage its lifecycle inside the owning controller.

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

Sidebar

Related Questions

Sorry I'm pretty new to iOS dev. I have a UITableView setup from cells
I am new to iOS dev and apologies if the answer is obvious...but it
I am new to iOS dev and there are questions I have that aren't
I have searched in Apple's iOS dev center but couldn't find anything quite right.
Pretty new to iOS dev, I feel I have a grasp of the basics.
This may sound a newbie question however I'm new to iOS dev. Are there
I am new iOS development but I know android at eclipse. For example I
I'm using the new iOS 5 core data concurrency options. I have two threads:
I'm quite new here. I have a problem with the new iOS 5.1 slide-in
I have experience on windows client dev, language c++, and Flash ActionScript3 dev, but

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.