2011-12-24 10 views
1

Interface Builderでタブバーを設定するために、「タブ付きアプリケーション」としてxcode 3でプロジェクトを開始しました。xcodeプロジェクトをタブ付きバーからプレーンに変更するにはどうすればいいですか?

私はプログラムでタブバーウィンドウを作成するのがよい理由があります。

私はたくさんのものを読んで、コード化されたタブバーで新しいプロジェクトを作成することができました。したがって、新しい空のアプリケーション(xcode 3では「ウィンドウベースアプリケーション」と呼ばれていたと思います)に基づいて、最初からタブバープロジェクトを作成する方法を理解したと思います。

しかし、「タブ付きアプリケーション」として開始された進行中のプロジェクトにそのコードを採用しようとすると、常に次のように表示されます。「アプリケーションの起動時にアプリケーションが起動すると、コンソール。

プロジェクトタイプを「タブ付きアプリケーション」から「空のアプリケーション」に遡って変更するにはどうすればよいですか? または、新しいプロジェクトを最初から開始し、すべてのソースファイルを古いものからコピーする唯一の方法はありますか?

はBTW:エラーメッセージをグーグルで、この優れたスレッドに私を導く:提案ソリューションの Applications are expected to have a root view controller at the end of application launch

残念ながらどれも私のために動作しません。そういうわけで、私の問題は最初からさまざまなタイプのプロジェクトに関係していると思います。

編集:現在のターゲットのコンパイラマクロ「FREE」に設定されたの

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent]; 


#ifdef FREE 

    window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

    self.tabBarController = [[[FcTabBarController alloc] init] autorelease]; 

    VotingMenuTVC *vc0 =[[[VotingMenuTVC alloc] initWithNibName:@"VotingMenuTVC" bundle:nil] autorelease]; 
    ChannelsTVC *vc1 =[[[ChannelsTVC alloc] initWithNibName:@"ChannelsTVC" bundle:nil] autorelease]; 

    NSArray* controllers = [NSArray arrayWithObjects:vc0, vc1, nil]; 
    tabBarController.viewControllers = controllers; 


    // Add the tab bar controller's current view as a subview of the window 
    float ver = [[[UIDevice currentDevice] systemVersion] floatValue]; 
    if (ver >= 4.0) { 
     self.window.rootViewController = self.tabBarController; 
    } else { 
     [window addSubview:[tabBarController view]]; 
    } 

    [window addSubview:[tabBarController view]]; 
    NSLog(@"RootViewController: %@",self.window.rootViewController); 
    NSLog(@"TabBarController: %@",self.tabBarController); 


#else 

    float ver = [[[UIDevice currentDevice] systemVersion] floatValue]; 
    if (ver >= 4.0) { 
     self.window.rootViewController = self.tabBarController; 
    } else { 
      [window addSubview:[tabBarController view]]; 
    } 

#endif 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

:私はdidFinshWithLaunchingコードを提供するように頼まれました。さもなければ、それはMainWindow.xibがまだそこにある(そしてうまく動作する)もう一つの才能のためにコンパイルします。現在、MainWindow.xibはBoundleの一部であり、FREEが設定されているものでもあります。しかし、それはターゲットのplistファイルのメインインターフェイスとして設定されていません。メインインターフェイスは空白です。

NSLogステートメント(およびデバッグ解析)によると、toolBarControllerプロパティは問題ありませんが、ウィンドウのrootViewControllerはnilです。これはわかりません。

Firoze LafeerからMainWindow.xibが依然として存在することを尋ねる質問がありましたので、それを変更する必要があります。私は結果を捨てて後でこの記事を更新します。

+0

MainWindowのペン先はまだありますか?ウィンドウとタブバーのコントローラーはそこにありますか?あなたのアプリケーションは何ですか:didFinishLaunchingWithOptions:どのように見えますか?おかげさまで –

答えて

0

答えは...分かりません。プロジェクトの設定やplistなどに何か間違っていました。

最後に私はそれを食べて、最初から新しいプロジェクトを開始しました。 (私は間違って見つけた他のビットと断片を識別する機会を得たので、その機会にARCに変更しました。)

私はすべてのソースをコピーしました:* .h、* .m、* .xib、 * .pngでもplistはありません。(私はまだローカライズされた文字列は持っていませんが、それがあればコピーしました) しかし、私は元のプロジェクトから削除したMainWindow.xibをコピーしませんでした。助けた皆に

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 

    [[UIApplication sharedApplication] setStatusBarStyle: UIStatusBarStyleBlackTranslucent]; 

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; 

    FcTabBarController *localTabBarConroller = [[FcTabBarController alloc] init]; 
    self.tabBarController = localTabBarConroller; 

    NSArray* controllers; 

    UserCentralVC *vc1 =[[UserCentralVC alloc] initWithNibName:@"UserCentralVC" bundle:nil user:nil userId:nil]; 
    ChannelsTVC *vc0 =[[ChannelsTVC alloc] initWithNibName:@"ChannelsTVC" bundle:nil] ; 
    AppMenuTVC *vc3  =[[AppMenuTVC alloc] initWithNibName:@"VotingMenuTVC" bundle:nil] ; //Re-Use another similar nib file. 

    UINavigationController* vnc0 = [[UINavigationController alloc] initWithRootViewController:vc0]; 
    UINavigationController* vnc1 = [[UINavigationController alloc] initWithRootViewController:vc1]; 
    UINavigationController* vnc3 = [[UINavigationController alloc] initWithRootViewController:vc3]; 

#ifdef FREE 
    controllers = [NSArray arrayWithObjects:vnc0, vnc1, vnc3, nil]; 
#else 
    VotingMenuTVC *vc2 =[[VotingMenuTVC alloc] initWithNibName:@"VotingMenuTVC" bundle:nil] ; 
    UINavigationController* vnc2 = [[UINavigationController alloc] initWithRootViewController:vc2]; 
    controllers = [NSArray arrayWithObjects:vnc0, vnc1, vnc2, vnc3, nil]; 
#endif 

    self.tabBarController.viewControllers = controllers; 


    // Add the tab bar controller's current view as a subview of the window 
    float ver = [[[UIDevice currentDevice] systemVersion] floatValue]; 
    if (ver >= 4.0) { 
     self.window.rootViewController = self.tabBarController; 
    } else { 
     [self.window addSubview:[self.tabBarController view]]; 
    } 

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

ありがとう:

最後にdidFinishLanuchingWithOptions方法は、まったく驚きではありません。場合によっては、解答が銀版に直接表示されなくても、話すのは役に立ちます。

皆様への季節の挨拶!

2

最初から開始する必要はありません。あなたがあなたのアプリケーションデリゲートであなたのUITabBarControllerを作成している場合は、それをウィンドウのルートビューコントローラとして設定する必要があります。 UITabBarControllerはUIViewControllerのサブクラスなので、これを簡単に行うことができます!

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{ 
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; 

    // Start creating your UITabBarController and set it up here: 
    UITabBarController *tabBarController; 
    // Finish creating your UITabBarController here 

    self.window.rootViewController = tabBarController; 

    [self.window makeKeyAndVisible]; 
    return YES; 
} 

おそらくtabBarControllerをプロパティにすることをお勧めします。

+0

それはそうじゃない。私はdidFinishWithLaunchingコードを質問に追加します。 –

+1

いいえ、これはそれです。ルートビューコントローラプロパティを設定することは、初期ビューコントローラを画面上に配置するための好ましい方法です。ウィンドウにサブビューを追加するのはSO 2010です。 –

+0

@MarkAdamsと同意します。サブビューを追加してオートレリースすると、とにかくレイジーなメモリ管理になります。 –

関連する問題