当我在注销时单击按钮时弹出不消除

时间:2014-09-06 10:56:21

标签: objective-c xcode uipopovercontroller

我正在使用弹出按钮将页面注销回Root视图控制器。我成功地回到根视图控制器,但弹出并没有解雇。它停留在Root视图控制器上这是我的代码

POPOVERVIEW CONTROLLER.H

@protocol MJSecondPopupDelegate;


#import <UIKit/UIKit.h>
#import "LoginViewController.h"
#import "TimeTableViewController.h"
@class TimeTableViewController;
@interface PopOverViewController : UIViewController <UIPopoverControllerDelegate>
{

//  UIPopoverController *popoverController;

}
@property (assign, nonatomic) id <MJSecondPopupDelegate>delegate;//ede ga
@property(strong,nonatomic) UIPopoverController *popoverController;
@property(nonatomic,strong)TimeTableViewController *TimeObj;
-(IBAction)logOut:(UIButton *)sender;
@end


@protocol MJSecondPopupDelegate<NSObject>
@optional
- (void)cancelButtonClicked:(PopOverViewController*)secondDetailViewController;
@end


POPOVERVIEW CONTROLLER.M

#import "PopOverViewController.h"

@interface PopOverViewController ()

@end

@implementation PopOverViewController
@synthesize delegate,TimeObj,popoverController;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}
-(void)SignOut{
    NSLog(@"protocol");
}
- (void)viewDidLoad
{
    [super viewDidLoad];

    NSLog(@"delegate value is %@",self.delegate);

    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
-(IBAction)logOut:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(cancelButtonClicked:)])
    {
        [self.delegate cancelButtonClicked:self];
        [self.popoverController dismissPopoverAnimated:YES];

    }
    }


MAINVIEW CONTROLLER.H


#import <UIKit/UIKit.h>

#import "NotesandReminders.h"
#import "Cell.h"
#import "SWRevealViewController.h"
#import "AvailableSessionViewController.h"
#import "ServiceConnector.h"
#import "AppDelegate.h"
#import "PopOverViewController.h"
#import "UIViewController+MJPopupViewController.h"


@class NotesandReminders;
@class PopOverViewController;
@protocol Popupprotocol <NSObject>

@optional
-(void)SignOut;

@end
@interface TimeTableViewController : UIViewController <UICollectionViewDataSource, UICollectionViewDelegate,MJSecondPopupDelegate>{

}


MAINVIEWCONTROLLER.M

#import "AvailableSessionViewController.h"

@interface TimeTableViewController ()
@end

@implementation TimeTableViewController
@synthesize pc,myCounterLabel,cancelSessionButtonOutlet,userButtonOutlet,saveButtonOutlet,timerr,collectionData,cancelSession,jsonData,secondviewcontroller,popoverController;

@synthesize startWeek,endWeek,startDateLabel,endDateLabel,todaysDate,startDate,endDate,dateForMatching,startDateToCall,endDateToCall;
@synthesize blueBarOutlet;
BOOL isLongPressed ;
int hours, minutes, seconds;
int secondsLeft;
int valueForBlueBar;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

// This method runs first when the screen is displayed
- (void)viewDidLoad
{
    [super viewDidLoad];
}

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
    if ([[segue identifier] isEqualToString:@"POPSegue"]) {
        PopOverViewController* userViewController = [segue destinationViewController];
        userViewController.delegate=self;

    }
}

AFTER LOG OUT IN ROOT VIEW CONTROLLER

我只是通过cntrl拖动到视图控制器并按模式选择PopOver来创建Pop

enter image description here

2 个答案:

答案 0 :(得分:1)

在以下行之后:

[self.popoverController dismissPopoverAnimated:YES];

添加

[self.popoverController.contentViewController.navigationController                 
                                              popToRootViewControllerAnimated:YES];

答案 1 :(得分:0)

这就是我设法摆脱它的方式

- (void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
   if ([[segue identifier] isEqualToString:@"POPSegue"]) {

       // settings popover is the global variable for  --> UIPopoverController *settingsPopOver;

       settingsPopOver = [(UIStoryboardPopoverSegue *)segue popoverController];
       _secondviewcontroller = (PopOverViewController *)settingsPopOver.contentViewController;
       _secondviewcontroller.delegate = self;


   }
}