Skip to content

Instantly share code, notes, and snippets.

@tonyarnold
Created May 15, 2012 07:11
Show Gist options
  • Save tonyarnold/2699700 to your computer and use it in GitHub Desktop.
Save tonyarnold/2699700 to your computer and use it in GitHub Desktop.
How do i call a parent ViewController's method?
#import <UIKit/UIKit.h>
#import "ViewController.h"
@interface Peekaboo : UIView
@property (nonatomic, retain) ViewController *parentView;
- (void) show;
@end
#import "Menu.h"
@implementation Menu
@synthesize parentView;
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
//do the bullshit here
}
return self;
}
- (void) show {
//this tells me that the parent view doesnt have a selector called showMyLabel
[parentView showMyLabel];
}
#import <UIKit/UIKit.h>
#import "Peekaboo.h"
@interface ViewController : UIViewController
- (void) showMyLabel;
//views
@property (nonatomic, retain) Peekaboo *peekabooView;
@end
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize peekabooView;
//view controller initiation
- (void)viewDidLoad {
//peekaboo view
peekabooView = [[Menu alloc] initWithFrame:CGRectMake(0, 0, 1024, 768)];
peekabooView.parentView = self;
[self.view insertSubview:peekabooView atIndex:1];
//create the label and hide it and stuff
}
- (void) showMyLabel {
//show the stupid label created above
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment