Question

I have 2 storyboard login.storyboard and main.storybard. On the *main.storyboard I use the SWRevealViewController. In the sidebarmenu of the SWRevealViewController I have a logout function, which do the logout and redirect to the login.storyboard. By doing this I get the warning:

Warning: Attempt to present <LoginViewController: 0x1551a630>  on <SidePanelViewController: 0x15645110> which is already presenting (null)

I think the SidePanelViewController (which is the SWRevealViewController) is not dissmissed correctly.

How do I do this exactly, to avoid this issue?

SidePanelViewController.h

#import <UIKit/UIKit.h>
#import "SingletonClass.h"

@interface SidePanelViewController : UITableViewController

@property (nonatomic, strong) SingletonClass *sshare;

@end

SidePanelViewController.m

#import "SidePanelViewController.h"
#import "SWRevealViewController.h"
#import <FacebookSDK/FacebookSDK.h>

@interface SidePanelViewController ()

@property (nonatomic, strong) NSArray *menuItems;

@end

@implementation SidePanelViewController

- (id)initWithStyle:(UITableViewStyle)style
{
    self = [super initWithStyle:style];
    if (self) {
        // Custom initialization
        DLog(@"inited");
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];

    self.sshare = [SingletonClass sharedInstance];
    self.menuItems = @[@"toSurroundStream", @"toImprint", @"logout"];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return [self.menuItems count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *CellIdentifier = [self getCellName:indexPath];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];

    // Configure the cell...
    if (indexPath.row == 0) {
        cell.textLabel.text = [NSString stringWithFormat:@"%@'s Stream", self.sshare.username];
    }

    return cell;
}

-(NSString *)getCellName:(NSIndexPath *)indexPath {
    NSAssert(self.menuItems, @"menuItems is missing");

    NSString *cellName = @"nix";

    if (indexPath.row < self.menuItems.count) {
        cellName = self.menuItems[indexPath.row];
    }

    DLog(@"cellName: %@", cellName);
    NSAssert(![cellName isEqualToString:@"nix"], @"No cellIdentifier found, check your menuLists. Consider IB as well");

    return cellName;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {

    NSAssert(self.menuItems, @"Array with menuItems does not exist");

    if (indexPath.item < self.menuItems.count) {
        NSString *cellName = [self getCellName:indexPath];

        DLog(@"cellName %@ call a method", cellName);

        if ([cellName isEqualToString:@"logout"]) {
            [self logout];
        }

-(void)logout {
    DLog(@"doing the logout");
    [[FBSession activeSession] closeAndClearTokenInformation];
    [self toLoginView];
}


-(void)toImprint {
#warning goto Imprint has to be implemented
}

-(IBAction)toLoginView {

    UIStoryboard *loginStoryboard = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
    UIViewController *loginViewController = [loginStoryboard instantiateInitialViewController];
    loginViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    [self dismissViewControllerAnimated:NO completion:nil];

    [self presentViewController:loginViewController animated:NO completion:nil];
}

- (void) prepareForSegue: (UIStoryboardSegue *) segue sender: (id) sender
{

    if ( [segue isKindOfClass: [SWRevealViewControllerSegue class]] ) {
        SWRevealViewControllerSegue *swSegue = (SWRevealViewControllerSegue*) segue;

        swSegue.performBlock = ^(SWRevealViewControllerSegue* rvc_segue, UIViewController* svc, UIViewController* dvc) {

            UINavigationController* navController = (UINavigationController*)self.revealViewController.frontViewController;
            [navController setViewControllers: @[dvc] animated: NO ];
            [self.revealViewController setFrontViewPosition: FrontViewPositionLeft animated: YES];
        };

    }

}

@end
Was it helpful?

Solution

This seems to work, at least I do not get the warning message again and the app works like desired.

SidePanelViewController.m

-(IBAction)toLoginView {

    UIStoryboard *loginStoryboard = [UIStoryboard storyboardWithName:@"Login" bundle:nil];
    UIViewController *loginViewController = [loginStoryboard instantiateInitialViewController];
    loginViewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

    // [self dismissViewControllerAnimated:NO completion:nil];
    [[self presentedViewController] dismissViewControllerAnimated:NO completion:nil];

    [self presentViewController:loginViewController animated:NO completion:nil];
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top