user393964
user393964

Reputation:

Access members of parent controller from UIPopoverController

How can I access the members of the controller that is calling a UIPopoverController inside that UIPopoverController?

The controller calling the UIPopoverController is set as a delegate on the popup (not sure if this helps me):

self.popover = [[UIPopoverController alloc] initWithContentViewController:theView];
[self.popover setDelegate: self];

Upvotes: 1

Views: 1007

Answers (2)

TheNavigat
TheNavigat

Reputation: 865

The best way is to use properties

@property double ivar (as I remember) This way you'll call it that way.

double test = self.popover.ivar;

or maybe double test = [self.popover ivar] . Both should work.

To do this, make sure you @synthesize ivar; in the .m file of the master controller or make a method as a getter

For the method, if it's a double,

- (double)ivar
{
     return 5;
}

is an example. If you're returning an instance variable, it's better to return a copy of it. Example:

return [ivar2 copy];

If you're using the method way, be sure that the method is the same name as the variable in the .h file.

Hope I helped!

EDIT: Replace that "double" thing with UIView, just saying

Upvotes: 0

Jesse Rusak
Jesse Rusak

Reputation: 57168

You access them in the same way as you access members from any other view controller: you need a reference to the parent view controller. For example, you could have a member variable on your popover view controller that points to the parent view controller. (You would want to make such a reference weak or unretained.) This member is often a "delegate" of the popover view controller.

You could set this on your theView before presenting it, or pass it to its initializer.

(I'm not sure, but you could also try looking at parentViewController or presentingViewController of the popover view controller.)

Upvotes: 1

Related Questions