tags:

views:

47

answers:

1

This seems like a simple thing, but can't get it to work.

I pass a variable into a UIViewController thourgh a standard property:

[aViewController setProposedDate:proposedWorkLog.entryDate];

which is retained by the controller, and possible changed. I have verified that in the controller, the data is modified.

But, after it is popped off the stack and I look in the calling view, the data has not been updated. Is there a way to pass this variable and have it retain the new value, or a way to pass back a response from a closing view controller?

Thanks!

+2  A: 

You need to pass it by reference. Objects in Objective-C are passed by reference because they (usually) are pointers, but primitives on the other hand, are (usually) not pointers. So you need to pass in a pointer to the primitive by using the address-of operator (&).

So your code should look like this:

[aViewController setProposedDate:&proposedWorkLog.entryDate];

You then need to change your method prototype to take a pointer to the primitive type (say int *).

Have a look at the way error handling with NSError works in Objective-C, it's using this methodology all over the place. http://www.cimgf.com/2008/04/04/cocoa-tutorial-using-nserror-to-great-effect/

Jacob Relkin