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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T19:00:52+00:00 2026-06-11T19:00:52+00:00

I have a view controller ( SecondViewController ) with a method named setupHomeScreen that

  • 0

I have a view controller (SecondViewController) with a method named setupHomeScreen that is called from another view controller (FirstViewController). This method is called after SecondViewController is initialized.

Within setupHomeScreen, a UIView is created that I would like to have the same boundaries as the main view, which will depend on whether the iPad is viewed in portrait or landscape mode.

When the method is first called (which is on app startup), the view is completely wrong, and an NSLog output shows the self.view.frame.size.width is equal to 0.0000.

If I navigate to ThirdViewController, and then back to SecondViewController, the view is correctly displayed and the self.view.frame.size.width value is 768.

I have tried a lot of different things to solve this, like putting the contents of the method inside the didRotateFromInterfaceOrientation and viewDidAppear: methods, but nothing seems to work.

Any help would be greatly appreciated.

  • 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-11T19:00:54+00:00Added an answer on June 11, 2026 at 7:00 pm

    When the method is first called (which is on app startup), the view is
    completely wrong, and an NSLog output shows the
    self.view.frame.size.width is equal to 0.0000.

    That’s probably because the view hasn’t been loaded yet. View controllers don’t load their views until they’re actually needed, which is usually when the views are about to be displayed for the first time. If your code is trying to find the view’s width before the view has been displayed, there’s a good chance that the view hasn’t been loaded. In Objective-C you’re allowed to send messages to nil, and the result will be 0 or nil, depending on the expected type.

    If I navigate to ThirdViewController, and then back to
    SecondViewController, the view is correctly displayed and the
    self.view.frame.size.width value is 768.

    That’s consistent with the explanation above; once you’ve displayed your SecondViewController view hierarchy, those views will have been loaded, and finding the width of your view is no problem.

    Simply accessing the view controller’s view property should be enough to cause the view hierarchy to be loaded. If you must, then, you can fix your problem by accessing self.view before calling setupHomeScreen. A much better solution, though, is to set your view’s width in the -viewDidLoad method of SecondViewController, which will maintain the view controller’s “lazy loading” behavior (and conserve memory) while still ensuring that your view’s width will be set when it’s needed.

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

Sidebar

Related Questions

I have to pass a value from one view-controller to another view-controller,my this code
So i have two view controller in FirstViewController and SecondViewController in FirstViewController NSMutableArray *array;
Hi i have two view controller: FirstViewController and SecondViewController FirstViewController.h #import <UIKit/UIKit.h> @interface FirstViewController:
I have a view controller initialized like this: HomeViewController *homeVC = [[HomeViewController alloc] initWithNibName:@HomeViewController
I have two view controllers name RootViewController and SecondViewController. In the FirstViewController I have
I have a view controller based app that contains several views that I display/hide
I have a view controller that houses a UIWebView. I want to display an
I have two view controller classes in my application delegate. I can change from
I have a view controller class that has to implement several protocols. Too keep
I have a UITableViewController which in it's tableView:didSelectRowAtIndexPath method, sets up a view controller,

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.