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;


}

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

同じコードを含む 2 つの異なる関数を呼び出していますが、.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 に答える