self.window setRootViewController无法处理xco​​de 6.1.1

时间:2015-03-12 08:00:55

标签: ios objective-c iphone xcode

我遇到了一些问题w.r.t XCode 6.1.1,这是我的代码

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    [[DBManager getSharedInstance] initWithdbFile];
    [[DBManager getSharedInstance] createtableScripts];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    containerViewController =[[CprViewController alloc] init];
    [containerViewController Setup];
    [self.window setRootViewController:containerViewController.containerViewController];
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    [self pickModel];
    return YES;
}

现在应用程序在较旧的XCode中正常工作,即5.1.1,但在XCode 6.1.1上进行模拟时,应用程序启动Launch图像并且没有响应,即执行结束于[self.window setRootViewController:containerViewController.containerViewController];并且它不会继续执行更多的代码行。它在控制台中没有显示错误。 (该应用程序可在具有最新操作系统(即iOS 8)的设备上运行。请帮助。

*编辑后 - 从这里开始

感谢您的帮助。这是我面临的问题, 这是我的AppDelegate文件

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{  
    [[DBManager getSharedInstance] initWithdbFile];
    [[DBManager getSharedInstance] createtableScripts];
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];  //Now Removed!!!
    containerViewController =[[CprViewController alloc] init];
    [containerViewController Setup];
    self.window.rootViewController = containerViewController.containerViewController;
    self.window.backgroundColor = [UIColor whiteColor];//Now Removed!!!
    [self.window makeKeyAndVisible];//Now Removed!!!
    [self pickModel];
    return YES;
}

现在我已按照您的建议删除了三行,现在继续执行

现在这是[containerViewController Setup]的代码;

-(void)Setup
{
     SideMenuViewController *leftMenuViewController = [SideMenuViewController  homeBookViewController];
    CprStartPageViewController *accounts=[[CprStartPageViewController alloc] initWithNibName:@"CprStartPageViewController" bundle:nil];
    self.navController= [[CprNavigationViewController alloc]
                         initWithRootViewController:accounts];
    self.containerViewController = [MFSideMenuContainerViewController                                                 containerWithCenterViewController:self.navController leftMenuViewController:leftMenuViewController
       rightMenuViewController:nil];
    [leftMenuViewController.passBookTable selectRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] animated:YES scrollPosition:0];
}

上面的代码附有一个侧面菜单(这里我附上一个左侧菜单) - 这段代码没有错误,即继续执行。 现在CprLoginViewController是我的parentViewController 即我提到的4屏幕的parentViewController,这是我4个屏幕的initWithNibName

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

现在错误发生在CprLoginViewController中我使用名为showNextPage的程序在这4页之间导航

-(void) showNextPage
{
    if (currentPage > numberPages)
        return;
    CprLoginSubViewController *controller;
        switch(currentPage)
        {
            case 0:
                controller = [[Corppersondtl alloc] initWithNibName:@"Corppersondtl" bundle:nil parentViewController:self];
                break;
            case 1:
                controller = [[CprLoginSub1ViewController alloc] initWithNibName:@"CprLoginSub1ViewController" bundle:nil parentViewController:self];
                break;
            case 2:
                controller = [[CprLoginSub2ViewController alloc] initWithNibName:@"CprLoginSub2ViewController" bundle:nil parentViewController:self];
                break;
            case 3:
                controller = [[CprLoginSub3ViewController alloc] initWithNibName:@"CprLoginSub3ViewController" bundle:nil parentViewController:self];
                break;
            case 4:
                controller = [[CprLoginSub4ViewController alloc] initWithNibName:@"CprLoginSub4ViewController" bundle:nil parentViewController:self];
            default:
                break;
        }
    CGRect rBounds;
    // add the required controller's view to scroll view
    if (controller.view.superview == nil)
    {
        CGRect frame = self.scrollView.frame;
        frame.origin.x = CGRectGetWidth(frame) * (currentPage);
        frame.origin.y = 0; 
        controller.view.frame = frame;
        [self addChildViewController:controller];
        [self.scrollView addSubview:controller.view];
        [controller didMoveToParentViewController:self];
        // just scroll to appropriate page
        rBounds = self.scrollView.bounds;
        rBounds.origin.x = CGRectGetWidth(rBounds) * currentPage;
        [self.scrollView scrollRectToVisible:rBounds animated:YES];
    }
    NSLog(@"scrollView is %lf", self.scrollView.frame.origin.y);
    viewOriginalbounds = rBounds; //self.scrollView.frame;
    currentPage++;
}

在上面的代码中,我附加了一个滚动视图,当键盘出现用于文本输入时向上滚动屏幕。 现在行if(controller.view.superview == nil)抛出了exc_bad_access错误。

1 个答案:

答案 0 :(得分:0)

只需删除那行代码

即可
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];