views:

359

answers:

2

Hi..

This may be very basic, but I just can`t figure out what to do, so thanks for any response...

I`m using a navigationcontroller and are currently on the second level in the stack. Here i set a string value and use popViewControllerAnimated to go back to first level in the stack.

What might be the best solution to use that string value from second level in the stack? I`ve tried to set a value in the first level manually in the second level, but I must be doing something wrong...

Thanks!

edit: Im very new to both objective-c and C in general so im still a bit confused :(

+1  A: 

Consider applying MVC pattern in your program - store the string value in a separate globally accessible storage class (in simple cases you can use application delegate or create a singleton object for this purpose). Then in your 2nd level controller you set the value in the storage and in 1st level you get it from the storage.

Vladimir
okey, thanks.. I`ll try that :)
Madoc
+1  A: 

Would it not be better to use a delegate pattern? You could define your top-level view as a delegate of the second-level view; you set the delegate property of the second-level controller before pushing it on the stack.

Once the string has been selected, before popping the second-level controller, call the delegate method with the string as its argument.

The advantage of that would be that it'd still work even if you have multiple instances of the same 2nd level controller (eg in a tabbed interface).

Oliver Mason