Wednesday 15 June 2011

iphone - Losing Contents of NSArray after ViewDidLoad -


I am working on my first iOS application: a cookbook that stores an array of recipe recipes The array is declared in a header file such as:

  @property (nonatomic, strong) NSArray * recipeArray;   

Views In theDidoadload method I fill the array like recipes from the XML file:

  Self. RecipeArerere = [[NSARAOL] InitVithArere: SERIFAFormXML];   

Within the viewDidload method, after that line of code I am able to successfully access the contents of the array.

The problem occurs when I want to use the array in the prepareForSegue method, the array seems blank. For the beginning of preparing for the right, for the SEGEE method, I put the test in the output statement:

  NSLog (@ "Segue to name name:% @", [myself. ક્રેਪੀરા [0] name]) ;   

And it is printed with "name called segu": (null)

Why does this happen? How can I get the contents of the array and how come it can not be saved after executing the visual diode method?

Many examples of a very common early mistake are an object, usually a view controller. This can happen if you instruct your view controller programmatically but the controller is also specified in the .xib or storyboard file. For example, if you have a Segue between two view controllers in your storyboard, but you are doing something like this:

  MyViewController * vc = [Storyboard Instinct ViewControllerWithIdentifier: @ "MyViewController"] ; Vc.dataFileName = @ "TheDataFile.txt";   

So many copies of the controller are very likely to be of your problem. You've got one that gives you the intent and the data file as the above, and then creates a storyboard when the user taps a button or otherwise activates the gigu.

Try entering a breakpoint in your -viewDidLoad method and see if the value of self is (this is the address of the view controller in this case) The times you kill it.

If your problem is actually, due to the many copies of your visual controller, you might think that if you do not instantiate it, then the view controller should be set. The answer is, of course, this is what is for -prepareForSegue: This is where you can tell the new view controller which files can get their data, or else You can set the visual controller so that it can do its job.

No comments:

Post a Comment