I wrote some code to hide a popover pressing a button but...it doesn't work (nothing new). I have a main view (I will call it A) with a button inside, pressing the button a popover is shown (I will call it B). The popover has another button inside which I want to use to close the popover and do something in A. Im other words, A is my main view, pressing a button I show a popover (B) to execute a login (credentials can be filled in).
Pressing the login button (the one within the popover) I call a service to check credentials and, in case the user is authenticated I want then close the popover and update my main view (A).
Below is my code
Popover header file (B)
#import <UIKit/UIKit.h>
@protocol MyPopoverDelegate <NSObject>
- (void) didLoginButton;
@end
@interface login : UIViewController
@property (nonatomic, assign) id<MyPopoverDelegate> delegate;
- (IBAction) doLogin;
@end
Popover implementation file (B)
#import "login.h"
@implementation login
@synthesize delegate;
....
..
- (IBAction) doLogin {
[self.delegate didLoginButton];
}
The button is linked with the doLogin action and it works fine (within the popover). I have some logic inside and it works well.
Main view header file (A)
#import <UIKit/UIKit.h>
#import "login.h"
@interface ViewController : UIViewController <UIPopoverControllerDelegate, MyPopoverDelegate> {
UIPopoverController *myPopoverController;
}
@property (nonatomic, retain) UIPopoverController *myPopoverController;
....
..
@end
Main view implementation file (A)
@synthesize delegate;
..
...
- (void) didLoginButton {
if ([myPopoverController isPopoverVisible]) {
NSLog(@"dismiss ok");
[myPopoverController dismissPopoverAnimated:YES];
}
}
....
..
Running my code and pressing the login button form the main view the popover appears. Pressing the button inside the popover nothing happens.
Basically, the didLoginButton method I have set into my main view file is never triggered and, of course, the popover is always visible. What I'm doing wrong?