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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T01:02:19+00:00 2026-05-18T01:02:19+00:00

I have a navigation based application where I place my custom views in the

  • 0

I have a navigation based application where I place my custom views in the navigation view.

First, I wanna know how to get the “navigation view”‘s frame so that I can place my custom view on it properly.
Also, I sometimes hide navigation bar and want to make sure I get the frame info correctly. (not with [[UIScreen mainScreen] bounds] )

Second, in general, how do I access the superview’s frame so that I can place a view accordingly?
I tried the following with no success.

-(void) loadView {
[super loadView];
UIView* myView = [[UIView alloc] initWithFrame: CGRectZero];
self.view = myView;
self.view.frame = self.view.superview.frame;
[myView release];
}

or setting the frame in layoutSubviews, but noticed layoutSubviews not getting called. I guess that’s because I don’t have any subviews in this particular view?

Thank you

-Edit-

with given answers, i now know that i need to set the view.frame to superview’s bounds.
The problem is that i’m unable to access superview inside viewDidLoad.
I can see that superview is correctly set in viewWillAppear but not in viewDidLoad.

I found out that viewDidLoad gets called at various times, such as when pushed by pushViewController or accessing self.view
I have the following code and viewDidLoad gets called from nil == controller.view.superview.

if (nil == controller.view.superview) {
    CGRect frame = scrollView.frame;
    frame.origin.x = frame.size.width * page;
    frame.origin.y = 0;
    controller.view.frame = frame;
    [scrollView addSubview:controller.view];
}

Since I can’t access superview from viewDidLoad, i can’t layout the view as i previously did in viewDidLoad. This seems so inconvenient and unnecessarily complex.
Any suggestion please?

  • 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-18T01:02:19+00:00Added an answer on May 18, 2026 at 1:02 am

    The superview property is nil until your view is added as a subview somewhere. In general, you can’t know what the superview will be within the loadView method.

    You could use autoresizing properties, as suggested by Costique. Check out the Resizing Subviews in the official UIView docs.

    You could also set the frame after the call to loadView, for example in something like this:

    MyViewController *myController = [[MyViewController alloc] init];
    myController.view.frame = window.bounds;
    [window addSubview:myController.view];
    

    By the way, it is generally safer to use the parent’s bounds property for the frame of the subview. This is because a parent’s bounds are in the same coordinate system as the subview’s frame, but the parent’s frame may be different. For example:

    UIView *parentView = /* set up this view */;
    UIView *subView = /* set up subview */;
    [parentView addSubview:subView];
    parentView.frame = CGRectMake(30, 50, 10, 10);
    subView.frame = subView.superview.frame;  // BAD!!!
    // Right now subView's offset is (30, 50) within parentView.
    subView.frame = subView.superview.bounds;  // Better.
    // Now subView is in the same position/size as its parent.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a navigation view with a cell that has something as simple as
We have a custom navigation webpart that uses the PortalSiteMapProvider of MOSS to build
I have a UIView with a navigation bar. How can I hide the navigation
I have a small tabbed navigation setup using CSS. When hovering over the tabs
I have created some rounded navigation tabs using CSS and am having trouble when
I have a page which work like a navigation and a iframe in this
Let's say I have a list of categories for navigation on a web app.
I'm using the following code to have a non-JS navigation: <ol id=navigation> <li id=home><a
I have a page with 3 layers, one for navigation, one for database records
I have a page using <ul> lists for navigation (Javascript changes the styling to

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.