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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:39:16+00:00 2026-05-26T09:39:16+00:00

I don’t understand why adding the init method to my view controller sets some

  • 0

I don’t understand why adding the init method to my view controller sets some ivars to (null) when some data are passed to this controller. Here’s the code I use to set some ivar values and call the associated view controller:

MyViewController *vc = [[MyViewController alloc] init];
vc.search_type = [NSMutableString stringWithString:@"buy"];
[self.navigationController pushViewController:vc animated:NO];

In MyViewController, the search_type ivar contains the @"buy" string stored in the previous view controller as expected. However, when I add the init method below, search_type always contains a (null) string when I try to use it in MyViewController:

(id)init
{
   self = [super init];
   if(self)
   {
        // some other code here
   }
   return self;
}

search_type is declared in interface as:

@property (nonatomic,retain) NSMutableString *search_type;

and synthesize in implementation file:

@synthesize search_type;
  • 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-26T09:39:17+00:00Added an answer on May 26, 2026 at 9:39 am

    It’s not entirely clear what you are trying to do, but if you are saying that search_type is nil in your init method where you have placed // some other code here, that’s because your view controller is initialised before you set that property.

    If you need to supply that object to your view controller before some more code runs, you have several options:

    • Create a custom initialiser such as initWithSearchType:.
    • Create a custom setter for that property.
    • Execute the code in viewDidLoad, viewWillAppear or similar method.

    Which of these is appropriate depends on exactly what it is you are doing.

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

Sidebar

Related Questions

Don't understand, if Data.Map is and [] is. I found this out while wondering
I don't understand where the extra bits are coming from in this article about
Don't know what to do with this error. How to add data in SQL
don't understand: in my controller: @json = User.all.to_gmaps4rails do |user| \Title\: \#{user.email}\ end in
Don't ask me why but i can't use this method because I need to
Don't dismiss this as a newbie question! It's not, I'm not, I've tried everything,
For some reason, after submitting a string like this Jack’s Spindle from a text
Don't they both have to convert to machine code at some point to execute
Don't think that I'm mad, I understand how php works! That being said. I
Don't need to do this right now but thinking about the future... What would

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.