0

The question might sound pretty naive, ut this is really troubling me. I am trying to set an instance variable by calling an instance method method of a ViewController from another view controller. Basically here are the steps

  1. I am in ViewController1
  2. Initialized an object of ViewController2
  3. Called an instance variable to set some values to the instance variable of ViewController2
  4. Then finally called the presentModalViewController to load the view controller
  5. Using the variables in viewWillAppear method, But the app crashes and on debugging it shows BAD_EXEC

I have tried printing the same in instance method and it prints there but crashing when trying to use somewhere outside the method.

I have also defined the property and also ynthesized the variable.

The only problem I can figure out is I am initializing the variable in methos ...Does that limit the scope of the variable.

Any kind of help would be highly appreciated.

Thanks in advance!!

0

2 Answers 2

1

Most likely you're running into a memory management error, and without code all I can advise is to make sure you are familiar with Cocoa's memory management system:

http://developer.apple.com/library/ios/#documentation/Cocoa/Conceptual/MemoryMgmt/MemoryMgmt.html

Sign up to request clarification or add additional context in comments.

1 Comment

thanks a lot i read the doc and got the mistake i was making it was not retaining the object when initialized in an instance method
1

If you are creating the properties for the instance variable and synthesizing the getters and setters, you should be able to set the instance variable using dot notation:

viewController2.variable = foo;

or by using the setter method:

[viewController2 setVariable:foo];

You should not be trying to access the instance variables directly. By default, the scope is set to Protected, meaning that you can only access it by methods in the class, it's subclasses, and in category extensions.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.