Question

I am getting an assertion failure error when debugging my app when trying to go from a modal view to a normal viewcontroller (PBSViewControllerDataDetail.h) (Not the original view controller that presented the modal view)

Essentially what I am trying to do is:

ViewController1, open modal view and do a async request. When it returns to then send the user on to a second, normal view controller which will present the user with the data gained within the modal view.

Everything else works until the modal trys to present the second view controller. I get the error (1st line is my NSLog output from within the method that trys to present the 2nd VC)

2013-09-22 07:24:11.410 PBSDashboard[566:1303] flipToDataView->Send user to PBSViewControllerDataDetail
2013-09-22 07:24:11.411 PBSDashboard[566:1303] *** Assertion failure in -[UIWindowController transition:fromViewController:toViewController:target:didEndSelector:], /SourceCache/UIKit_Sim/UIKit-2380.17/UIWindowController.m:211

PLEASE NOTE: I am not using a NavigationViewController within this project and have considered restarting the entire lot and use one but at the moment I am just trying to understand how to go from Modal to normal ViewController that is not the original one.

I have tried cleaning down the targets, recreating the 2nd VC from scratch, both without success.

Code snippets

PBSRequestViewController.h

#import <UIKit/UIKit.h>
#import "Unirest.h"
#import "PBSDaySales.h"

@class PBSRequestViewController;

@protocol PBSRequestViewControllerDelegate
    - (void) requestViewControllerDidFinish:(PBSRequestViewController *)controller;
@end

@interface PBSRequestViewController : UIViewController

@property (weak, nonatomic) IBOutlet id <PBSRequestViewControllerDelegate> delegate;
@property (weak, nonatomic) IBOutlet NSString *calendType;
@property (weak, nonatomic) IBOutlet NSString *targetDate;
@property (weak, nonatomic) IBOutlet UILabel *messageLabel;


- (void) runUnirestRequest:(NSString*)urlToGet;
- (void) loadDefaultSettings;
- (NSString*) buildRequestUrl:(NSString*)serverUrl withPort:(NSString*)serverPort withCalenderType:(NSString*)calendarType withDateStringParameter:(NSString*)selectedTargetDate;

- (IBAction)btnBack:(id)sender;

- (PBSDaySales*) deserializeJsonPacket:(NSDictionary*)httpJson;
- (void)createActivityIndicator;
- (void)flipToDataView;

@end

PBSRequestViewController.m (Just the calling function for 2nd vc)

// Method will forward the user on to the data view.
// Used after the uniRestRequest is completed and data exists.
- (void) flipToDataView
{
    NSLog(@"flipToDataView->Send user to PBSViewControllerDataDetail");
    PBSViewControllerDataDetail *dataVc = [[PBSViewControllerDataDetail alloc] initWithNibName:@"PBSViewControllerDataDetail" bundle:nil];

    dataVc.daySalesData = daySalesFigures;

    [self presentViewController:dataVc animated:YES completion: nil];
}

PBSViewControllerDataDetail.h

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

@interface PBSViewControllerDataDetail : UIViewController
    @property (weak, nonatomic) PBSDaySales *daySalesData;
@end

PBSViewControllerDataDetail.m

#import "PBSViewControllerDataDetail.h"

@interface PBSViewControllerDataDetail ()

@end

@implementation PBSViewControllerDataDetail

@synthesize daySalesData;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSLog(@"View loaded");
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

PBSAppDelegate.m

#import "PBSAppDelegate.h"

#import "PBSViewController.h"

@implementation PBSAppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    // Override point for customization after application launch.
    if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[PBSViewController alloc] initWithNibName:@"PBSViewController_iPhone" bundle:nil];
    } else {
        self.viewController = [[PBSViewController alloc] initWithNibName:@"PBSViewController_iPad" bundle:nil];
    }
    self.window.rootViewController = self.viewController;
    [self.window makeKeyAndVisible];
    return YES;
}
Was it helpful?

Solution

To go from modal to 'normal' you should be presenting the 'normal' controller behind the modal controller (often in your root nav controller) and then dismissing the modal. Having a nav controller as the root view controller of the window makes life easier because it can be the host of the modal. At no point should you be trying to use a transition from a modal to 'normal', it's always a dismiss of the modal. The modal is on a conceptually different level within the screen layers if that makes sense...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top