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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T12:07:44+00:00 2026-05-25T12:07:44+00:00

edit : ok, what i’ve learned is you might choose between initWithNibName or initWithCoder,

  • 0

edit : ok, what i’ve learned is you might choose between initWithNibName or initWithCoder, depending if you use a .xib or not. And “init” is just not the constructor method for UIVIewController.

This might seem to be a fairly simple question, but I’m not sure about the answer : I’ve read that this method “is only used for programatically creating view controllers”, and in the doc : “It is loaded the first time the view controller’s view is accessed”

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
        // Custom initialization
    }
    return self;
}

Ok so to understand it a bit more :

What would you write as “custom initialization” into this method?
When should you implement this method, like that in the code, if you can just write it after allocating your viewController (example : MyVC *myvc = [[MyVC alloc] initWithNibName:...bundle...];)

Thanks for your answer

  • 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-25T12:07:45+00:00Added an answer on May 25, 2026 at 12:07 pm

    Usually I do this:

    // Initialize controller in the code with simple init
    MyVC *myVC = [[MyVC alloc] init];
    

    Then do this in my init method:

    - (id)init {
        self = [super initWithNibName:@"MyVC" bundle:nil];
    
        if (!self) return nil;
    
        // here I initialize instance variables like strings, arrays or dictionaries.
    
        return self;
    }
    

    If controller needs some parameters from the initializee, then I write custom initWithFoo:(Foo *)foo method:

    - (id)initWithFoo:(Foo *)foo {
        self = [super initWithNibName:@"MyVC" bundle:nil];
    
        if (!self) return nil;
    
        _foo = [foo retain];
    
        return self;
    }
    

    This allows simplification of initialization as well as extra initializers for your view controller if it can be initialized from different locations with different parameters. Then in initWithFoo: and initWithBar you’d simply call init which calls super and initializes instance variables with default values.

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

Sidebar

Related Questions

EDIT: Learned that Webmethods actually uses NLST, not LIST, if that matters Our business
Edit: I would like to model a 1 to 0:1 relationship between User and
Edit: an important piece might be that I'm calling a cfc method via ajax...
Edit ok, great feedback here, got me pointed in the right direction. Use case
EDIT : Summary : Git does not allow dates before 1973/03/03 09:46:40 (epoch+100000000s) given
Edit: Rewritting question I use the Project Management Library from http://dlhsoft.com/Home.aspx in my WPF
Edit : Array should be CvMat or IplImage is not an error message specific
EDIT: Note. I should have mentioned I'm not interested in using the .Select, DataRowView,
EDIT: Guys, sure I meant Entity Framework not ASP.NET MVC, it was a typo
[Edit: Apparently, this is only an issue for arrays and FoxyBOA's answer might direct

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.