2011-08-03 12 views
2

今、私は8種類のビューを持つビューベースのアプリケーションを作成しました。 3つのビューにタブバーを表示したい。このタブバーには3つのアイテムがあり、ユーザーは3つのビューに切り替えることができます。ビューベースのアプリケーションに3つのアイテムを含むタブバーを追加する

どうすればいいですか?どうもありがとう。

AppDelegate.h

@interface LoginPageAppDelegate : NSObject <UIApplicationDelegate, UITabBarControllerDelegate> { 
    UIWindow *window; 
    LoginPageViewController *viewController; 
    UITabBarController *tabBarController; 

} 

@property (nonatomic, retain) IBOutlet UIWindow *window; 
@property (nonatomic, retain) IBOutlet LoginPageViewController *viewController; 
@property (nonatomic, retain) IBOutlet IBOutlet UITabBarController *tabBarController; 


@end 

AppDelegate.m

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {  
    tabBarController = [[UITabBarController alloc] init]; 
    tabBarController.delegate=self; 

    RequestPage* requestPage = [[RequestPage alloc] init]; 
    UIViewController *RequestPageView = [[UIViewController alloc] initWithRootViewController:requestPage]; 

    StatusPage* statusPage = [[StatusPage alloc] init]; 
    UIViewController *StatusPageView = [[UIViewController alloc] initWithRootViewController:statusPage]; 
    NSArray* controllers = [NSArray arrayWithObjects:RequestPageView, StatusPageView, nil]; 
    tabBarController.viewControllers = controllers; 

    [window addSubview:tabBarController.view];   

    [self.window makeKeyAndVisible]; 

    return YES; 
} 

RequestPage.m

- (id)init { 
    self.title = @"Request Page"; 
    UIImage* anImage = [UIImage imageNamed:@"3.png"]; 
    UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"Request Page" image:anImage tag:2]; 
    self.tabBarItem = theItem; 
    [theItem release]; 
    return self; 
} 

答えて

3

ビューベースのアプリケーションから開始する必要があります。 appDelegateファイルにUITabbarControllerを作成します。

Appdelegate.h

UITabBarController *tabBarController; 
// set properties 

Appdelegate.m

// Synthsize 

tabBarController = [[UITabBarController alloc] init]; 
tabBarController.delegate=self; 

//Adding Search,Nearby,Map,AboutUs,Favorites Tabs to tabBarController 
Search * search = [[Search alloc] init]; 
UINavigationController *searchNav = [[UINavigationController alloc] initWithRootViewController:search]; 

Nearby* nearby = [[Nearby alloc] init]; 
UINavigationController *nearbyNav = [[UINavigationController alloc] initWithRootViewController:nearby]; 

Map* map = [[Map alloc] init]; 
UINavigationController *mapNav = [[UINavigationController alloc] initWithRootViewController:map]; 

AboutUs* aboutUs = [[AboutUs alloc] init]; 
UINavigationController *aboutUsNav = [[UINavigationController alloc] initWithRootViewController:aboutUs]; 

Favorites* favorites = [[Favorites alloc] init]; 
UINavigationController *favoritesNav = [[UINavigationController alloc] initWithRootViewController:favorites]; 

NSArray* controllers = [NSArray arrayWithObjects:searchNav,nearbyNav,mapNav,aboutUsNav,favoritesNav, nil]; 
tabBarController.viewControllers = controllers; 

[window addSubview:tabBarController.view];  

あなたはナビゲーションコントローラまたは専用ビューコントローラを配置するタブに応じて管理することができます。もし上記のビューコントローラのそれぞれにおけるその後

を使用すると、タブ名と画像を設定することが可能な

- (id)init {} 

を実装する必要があります。

更新

- (id)init { 
     self.title = @"Second"; 
     UIImage* anImage = [UIImage imageNamed:@"3.png"]; 
     UITabBarItem* theItem = [[UITabBarItem alloc] initWithTitle:@"Second" image:anImage tag:2]; 
     self.tabBarItem = theItem; 
     [theItem release]; 
    return self; 
} 
+0

タブ名とイメージを設定するにはどうすればよいですか? –

+0

私は自分の答えを編集しました。それを確認してください。 – Nitish

+0

迅速な返信をありがとうございます。私は何が間違っているのか分かりません。これで本当に新しいです。私が行ったことで私の質問を編集しました。どうぞご覧ください。アプリの起動中にクラッシュします。 –

1

その良好複数のビューをナビゲートするUINavigationControllerと共にタブバーベースのアプリケーションを作成します。

+0

ゴナは再び新たに開始する退屈なこと。私はナビゲートに問題がなかったので、私はこの問題の迅速な解決策を模索しようとしていました。 –

+0

上から下に新鮮なものを始める必要はありません。作成したビューを新しく作成したタブバーベースのアプリケーションにコピー&ペーストするだけで、非常に多くの手動コードを煩わしく管理する必要がありません。とにかく... –

関連する問題