views:

23

answers:

1

I'm new to objective-c and need some help setting this up. Basically, there's the main view and it opens a pop over view. the pop over has a segmented control with 2 buttons. clicking btn1 should save 0 to a variable in the main view, and btn2 should save 1. Closing the reopening the popover should display the previously selected value.

MainViewController.h
NSInteger data;
MainViewController.m

PopOverViewController.h
PopOverViewController.m

Could someone give me some tips on how to do this?

A: 

There's no straight forward way to "return" a value from a sub controller, so you can use a simple pointer.

In PopOverViewController, declare an instance variable

NSInteger *data;

...

@property NSInteger * data;

And then set the pointer after you alloc the controller

popOverController.data = &data;

Later btn1 will run

*data = 0;

etc... This sets the value in the original data variable.

whooops
do i need to retain the property?
Fasid
so with this will changing the variable in main controller also change the value of the variable in the popover controller? and vice versa?
Fasid
No need to retain it because you aren't using Objective C's memory management.
whooops
Yes, the data is stored in the original variable. The second variable is a pointer, so it "points" to the original variable. There is only one copy of the actual information.
whooops
Did this work for you? You should accept my answer if it did.
whooops