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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T06:24:45+00:00 2026-05-29T06:24:45+00:00

I write a simple ios app. All of my views are created programmatically. Here

  • 0

I write a simple ios app. All of my views are created programmatically.
Here is some code

rootViewController.m

-(void)loadView
{
  UIView *view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
  self.view = view;
  self.view.backgroundColor = [UIColor greyColor];
}

In appDelegate I add rootViewController view to the window and everything work fine. But if expression

self.view = view

is removed rootViewController is not loaded in window.
Why is this happening ?

  • 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-29T06:24:46+00:00Added an answer on May 29, 2026 at 6:24 am

    Because if you don’t set the view property of the view controller then the view controller’s view is nil and a nil view means a blank screen.

    What would you expect to happen if you try to display a view controller with a nil view?

    Normally view controllers create their own empty view (or load it from a nib file) when you first reference their view property, but since you are overriding the loadView method, you have to set the view yourself.

    Your code may be easier to understand if written like this – the view variable and view property having the same name may be the source of your confusion:

    -(void)loadView
    {
      self.view = [[UIView alloc]initWithFrame:[UIScreen mainScreen].applicationFrame];
      self.view.backgroundColor = [UIColor grayColor];
    }
    

    Incidentally, if you aren’t using ARC, you need to autorelease the UIView above before you assign it to the self.view or you’ll have a leak.

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

Sidebar

Related Questions

I'm trying to write a simple painting app for iOS as a first non-trivial
I am trying to write simple Visual Studio Add-In for code generation. In my
I'm trying to write simple proxy server for some purpose. In it I use
i write a simple webservice code in asp.net when i build the service and
I write a simple piece of code that creates a div and assign it
I write a simple OLAP viewer for my web-site. Here are the classes (abstract
Back Story: I was approached to write an app, but iOS isn't something that
I'm planing to write simple iOS game and I'm curious which view control to
I wrote simple iOS app which countdown the time til midnight. I have single
Hello i'm trying to make a simple ios app with tabs and navigation .

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.