I was digging around on SO and thought I had figured out how to do this but my test failed. I’m trying to close a popovercontroller from the viewcontroller that is launched/contained (I’m still a bit fuzzy on the poc and vc relationship) by it.
In my viewcontroller .h I have this:
@interface OAI_vcOperatingRooms : UIViewController {
OAI_ColorManager* colorManager;
OAI_FileManager* fileManager;
UIPopoverController* myPopOverController;
}
@property (nonatomic, weak) UIPopoverController* myPopOverController;
- (void) closeVC : (id) sender;
and in the .m file
UIButton* btnClose = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[btnClose addTarget:self
action:@selector(closeVC:)
forControlEvents:UIControlEventTouchDown];
[btnClose setTitle:@"Close" forState:UIControlStateNormal];
btnClose.frame = CGRectMake(10.0, 210.0, 160.0, 40.0);
[self.view addSubview:btnClose];
- (void) closeVC : (id) sender {
[myPopOverController dismissPopoverAnimated:YES];
}
in the uiview that calls the popovercontroller, I’ve referenced the viewcontroller and added this:
//operating rooms
controller2 = [[OAI_vcOperatingRooms alloc] initWithNibName:@"OAI_vcOperatingRooms" bundle:nil];
popoverController2 = [[UIPopoverController alloc] initWithContentViewController:controller2];
controller2.myPopOverController = popoverController2;
No errors but nothing happens when I hit the close button. Is it possible to reference a POC from within the VC?
Thanks
I believe ott’s comment is on to something – try using a
strongproperty instead of aweakone. Aweakproperty is likely to get set to nil by ARC immediately after its last use. Astrongproperty will stick around for the lifetime of its parent object (in this case, yourUIViewControllersubclass), unless you set it tonilearly.Note: you probably don’t need
UIPopoverController *myPopOverController;in your interface, since Xcode will automatically generate_myPopOverControlleras a backing variable.