簡體   English   中英

將帶有3個項目的標簽欄添加到基於視圖的應用程序

[英]Adding tab bar with 3 items to a view based application

因此,現在我已經創建了具有8個不同視圖的基於視圖的應用程序。 我希望它在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;
}

您需要從基於視圖的應用程序開始。 然后創建一個UITabbarController在你appDelegate文件。

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;
}

最好創建一個基於Tabbar的應用程序以及UINavigationController來瀏覽多個視圖。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM