0

我正在尝试将 iphone 应用程序转换为通用应用程序,这是我的代码

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPhone" bundle:nil];

        //  self.viewController = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];
        [self.window addSubview:self.viewController.view];
        [self.timer invalidate];
        self.timer = nil;
        self.timer = [NSTimer scheduledTimerWithTimeInterval: 3 target: self selector: @selector (pullnextview) userInfo: nil repeats: YES];
    } else {
        self.viewController = [[ViewController alloc] initWithNibName:@"ViewController_iPad" bundle:nil];
        [self.window addSubview:self.viewController.view];
        [self.timer invalidate];
        self.timer = nil;
        self.timer = [NSTimer scheduledTimerWithTimeInterval: 3 target: self selector: @selector (Ipadpullnextview) userInfo: nil repeats: YES];
    }

==================================================== =================================

-(void)pullnextview
{
    [self.viewController.view removeFromSuperview];
    [self.timer invalidate];
    self.timer = nil;
    NSArray *viewsArray;
    //create the first view controller

    SearchViewController *navController0 = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];

    navController0.tabBarItem.image = [UIImage imageNamed:@"search.png"];
    [navController0 setTitle:@"Neuen Termin buchen"];

    //create the navigation controller and use NavRootController as its root
    UINavigationController *nav0 = [[UINavigationController alloc] initWithRootViewController:navController0];
    UINavigationController *nav;
    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
    int uid = [standardUserDefaults integerForKey:@"dmloginid"];
    [standardUserDefaults synchronize];

    if(uid>0)
    {

        SearchViewController *navController = [[SearchViewController alloc] initWithNibName:@"SearchViewController" bundle:nil];
        navController.tabBarItem.image = [UIImage imageNamed:@"appointment.png"];
        [navController setTitle:@"Meine Termine"];
        nav = [[UINavigationController alloc] initWithRootViewController:navController];

    }
    else
    {
        LoginViewController *navController = [[LoginViewController alloc] initWithNibName:@"LoginViewController" bundle:nil];
        navController.tabBarItem.image = [UIImage imageNamed:@"appointment.png"];
        [navController setTitle:@"Meine Termine"];
        nav = [[UINavigationController alloc] initWithRootViewController:navController];

    }


    SettingsViewController *navController3 = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
    navController3.tabBarItem.image = [UIImage imageNamed:@"setting.png"];
    [navController3 setTitle:@"Einstellungen"];

    //create the navigation controller and use NavRootController as its root
    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:navController3];
    viewsArray = [NSArray arrayWithObjects:nav0,nav,nav3, nil];
    UITabBarController *tabbarController = [[UITabBarController alloc] init];
    tabbarController.view.frame = CGRectMake(0,0,320,460);
    //then tell the tabbarcontroller to use our array of views
    [tabbarController setViewControllers:viewsArray];

    //then the last step is to add the our tabbarcontroller as subview of the window
    self.window.rootViewController = tabbarController;


}

-(void)Ipadpullnextview
{
    [self.viewController.view removeFromSuperview];
    [self.timer invalidate];
    self.timer = nil;
    NSArray *viewsArray;
    //create the first view controller

    SearchViewController *navController0 = [[SearchViewController alloc] initWithNibName:@"IpadSearchViewController" bundle:nil];

    navController0.tabBarItem.image = [UIImage imageNamed:@"search.png"];
    [navController0 setTitle:@"Neuen Termin buchen"];

    //create the navigation controller and use NavRootController as its root
    UINavigationController *nav0 = [[UINavigationController alloc] initWithRootViewController:navController0];
    UINavigationController *nav;
    NSUserDefaults *standardUserDefaults = [NSUserDefaults standardUserDefaults];
    int uid = [standardUserDefaults integerForKey:@"dmloginid"];
    [standardUserDefaults synchronize];

    if(uid>0)
    {

        SearchViewController *navController = [[SearchViewController alloc] initWithNibName:@"IpadSearchViewController" bundle:nil];
        navController.tabBarItem.image = [UIImage imageNamed:@"appointment.png"];
        [navController setTitle:@"Meine Termine"];
        nav = [[UINavigationController alloc] initWithRootViewController:navController];

    }
    else
    {
        LoginViewController *navController = [[LoginViewController alloc] initWithNibName:@"IpadLoginViewController" bundle:nil];
        navController.tabBarItem.image = [UIImage imageNamed:@"appointment.png"];
        [navController setTitle:@"Meine Termine"];
        nav = [[UINavigationController alloc] initWithRootViewController:navController];

    }


    SettingsViewController *navController3 = [[SettingsViewController alloc] initWithNibName:@"IpadSettingsViewController" bundle:nil];
    navController3.tabBarItem.image = [UIImage imageNamed:@"setting.png"];
    [navController3 setTitle:@"Einstellungen"];

    //create the navigation controller and use NavRootController as its root
    UINavigationController *nav3 = [[UINavigationController alloc] initWithRootViewController:navController3];
    viewsArray = [NSArray arrayWithObjects:nav0,nav,nav3, nil];
    UITabBarController *tabbarController = [[UITabBarController alloc] init];
    tabbarController.view.frame = CGRectMake(0,0,320,460);
    //then tell the tabbarcontroller to use our array of views
    [tabbarController setViewControllers:viewsArray];

    //then the last step is to add the our tabbarcontroller as subview of the window
    self.window.rootViewController = tabbarController;


}

==================================================== =================================

我正在调用包含相同代码但 .xib 不同的两个不同函数。之后,当我去运行代码时,这个错误来了。

==================================================== =================================

 *** Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: '-[UIViewController _loadViewFromNibNamed:bundle:] loaded the "IpadSearchViewController" nib but the view outlet was not set.'

谁能帮我。我是本节的新手。

4

1 回答 1

3

转到您的 iPad XIB 并通过右键单击视图连接视图插座,然后将视图的引用插座连接到文件所有者。它应该可以正常工作

于 2012-09-11T10:05:16.893 回答