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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T18:12:09+00:00 2026-05-28T18:12:09+00:00

Wish to know more about the practical differences between init and initWithNibName . SO

  • 0

Wish to know more about the practical differences between init and initWithNibName. SO answers such as this suggests that it is better to call “initWithNibName” indirectly through “init“.

  1. Are there any circumstances that we need to define “init” and
    “initWithNibName” differently ?
  2. Is it possible that any Nib file needs to be loaded more than once
    during a single program execution ?
  3. Are questions 1 & 2 inter-related ?
  • 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-28T18:12:09+00:00Added an answer on May 28, 2026 at 6:12 pm

    It is not better to call initWithNibName: indirectly through init. You just want to call initWithNibName: at some point. You can do that externally or internally. Some people think it’s better to do it internally. I actually have a class called “LayoutUtil” that I keep layout-related helper methods to avoid writing tedious piece of layout-related code over and over. Here is my code to load a UIViewController:

    + (id)loadController:(Class)classType {
        NSString *className = NSStringFromClass(classType);
        UIViewController *controller = [[classType alloc] initWithNibName:className bundle:nil];
        return controller;
    }
    

    And then I can just do:

    MyViewController *c = [LayoutUtil loadController:[MyViewController class]];
    

    If you want, you could add a method called ughhhh to a class and call it in there, it doesn’t matter at all. The point is that it is not a better practice to call initWithNibName in the init method though, you just want to make sure you call it at some point when initiating a UIViewController.

    - (id)ughhhh
    {
       self = [super initWithNibName:@"Myview" bundle:nil];
       if (self != nil)
       {
       }
       return self;
    }
    

    A nib file can definitely need to be loaded more than once. Everytime you call initWithNibName on a UIViewController the xib has to be loaded. A lot of people load UIViews that are not owned by a UIViewController like this:

    [[NSBundle mainBundle] loadNibNamed:@"nameOfXIBFile" owner:self options:nil];
    

    Everytime you call this function you will be loading the nib.

    There are certain cases where a nib can be cached. An example would be a UITableView — but the table view implements it’s own cache. The operating system isn’t doing any caching automatically.

    init and initWithNibName: are related in that initWithNibName: automatically calls init on an object.

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

Sidebar

Related Questions

I guess this query is a little basic and I should know more about
I wish to know all the pros and cons about using these two methods.
I wish to know is there any way that I can create the threads
I wish Subversion had a better way of moving tags. The only way that
EDIT: This question is more about language engineering than C++ itself. I used C++
I wish to know how Old Linux scheduling algorithm SJF (shortest job first) calculates
I wish to know the way to add ASP.NET (Machine_Name\IIS_IUSRS) to user role in
In text fields of my JSP, I wish to know whether user is typing
I have used the String Tokenizer in Java. I wish to know if there
I wish to implement my software on a shareware basis, so that the user

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.