Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

neil.b

macrumors member
Original poster
Nov 20, 2008
65
0
I've got an instance method in my view controller that I want to call from one of the view controller's sub views.

Is there a way to do this? In Actionscript (for example) you can use parent.function but for the life of me I can't figure it out in ObjC.

Thanks
 

jnic

macrumors 6502a
Oct 24, 2008
567
0
Cambridge
I've got an instance method in my view controller that I want to call from one of the view controller's sub views.

Is there a way to do this? In Actionscript (for example) you can use parent.function but for the life of me I can't figure it out in ObjC.

Thanks

You could extern the view controller you want to access and then call that from the sub view, i.e.:

Code:
extern YourViewController *yvc;

in YourViewController.h;

Code:
YourViewController *yvc;

in YourViewController.m (before you declare the @implementation); and

Code:
[yvc yourInstanceMethod];

from the sub view. (You'll need to #import YourViewController.h into YourSubView.m.)
 

firewood

macrumors G3
Jul 29, 2003
8,141
1,384
Silicon Valley
I would stick a pointer to the superview inside the subview object, and have that pointer populated by the superview on init or load. That way the superview is more in control of its own use.

.
 

neil.b

macrumors member
Original poster
Nov 20, 2008
65
0
I would stick a pointer to the superview inside the subview object, and have that pointer populated by the superview on init or load. That way the superview is more in control of its own use.

.

Nice. I like that one.

:)
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.