Friday, 27 September 2013

Dismissing Popover View with Storyboard Segues

Dismissing Popover View with Storyboard Segues

I've been googling and searching all over stack exchange for the right
answer, but I can't seem to find it. What I have is a popover view that is
presented via a popover segue, and when a button is clicked inside the
popover view, I want it to be dismissed and display a UIAlert. Here is the
code I have thus far, with what I have gathered from other answers but
dosn't work:
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"popOverSegue"]) {
if ([segue isKindOfClass:[UIStoryboardPopoverSegue class]]) {
UIStoryboardPopoverSegue *popoverSegue = (UIStoryboardPopoverSegue
*)segue;
self.myPopoverController = popoverSegue.popoverController;
}
}
}
- (void)methodThatShouldCauseMyPopoverToCloseAnimated:(BOOL)animated
{
[self.myPopoverController dismissPopoverAnimated:animated];
NSLog(@"Dismissed");
}
-(IBAction)presentPopoverView:(id)sender {
if (!popOverViewIsShown){
[self performSegueWithIdentifier:@"popOverSegue" sender:self];
popOverViewIsShown = YES;
}else {
[self methodThatShouldCauseMyPopoverToCloseAnimated:YES];
popOverViewIsShown = NO;
}
}
- (IBAction)logoutMethod:(id)sender {
[self methodThatShouldCauseMyPopoverToCloseAnimated:YES];
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Logout"
message:@"Are you sure?"
delegate:self
cancelButtonTitle:@"Cancel"
otherButtonTitles:@"OK", nil];
alert.tag = 0;
[alert show];
}
I'm suspecting that when I call methodThatShouldCauseMyPopoverToClose that
myPopoverController is equal to nil. Any suggestions? Thank you so much!
:)

No comments:

Post a Comment