TabBar的使用,一个应用程序中,tablebar始终存在于界面下方

来源:互联网 发布:uml数据库表示法 编辑:程序博客网 时间:2024/05/05 21:47

如果你想做一个类似于满座的下面的tablebar下面的功能,

那么恭喜你找对了,直接上代码

首先在AppDelegate.h里面添加以下代码

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate,UITabBarDelegate,UITabBarControllerDelegate>

@property (strong, nonatomic) UIWindow *window;

@property(nonatomic,retain)UITabBarController*tabBarController;

@end

然后在AppDelegate.m

导入所创建类的头文件

然后在

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

{

    self.window = [[[UIWindowalloc] initWithFrame:[[UIScreenmainScreen] bounds]] autorelease];

    

    _tabBarController=[[UITabBarControlleralloc]init];

    _tabBarController.delegate=self;


    MainViewController*first=[[MainViewControlleralloc]init];

    first.tabBarItem.title=@"主页";

    first.tabBarItem.image=[UIImageimageNamed:@"a.png"];


    NearViewController *second=[[NearViewControlleralloc]init];

    second.tabBarItem.title=@"周边";

    second.tabBarItem.image=[UIImageimageNamed:@"c.png"];

    

    SearchViewController*third=[[SearchViewControlleralloc]init];

    third.tabBarItem.title=@"搜索";

    third.tabBarItem.image=[UIImageimageNamed:@"e.png"];

   

    AppSetingViewController*fourth=[[AppSetingViewControlleralloc]init];

    fourth.tabBarItem.title=@"满座";

    fourth.tabBarItem.image=[UIImageimageNamed:@"s.png"];

    

    UINavigationController * nav1 =[[UINavigationControlleralloc]initWithRootViewController:first];

    UINavigationController * nav2 =[[UINavigationControlleralloc]initWithRootViewController:second];

    UINavigationController * nav3 =[[UINavigationControlleralloc]initWithRootViewController:third];

    UINavigationController * nav4 =[[UINavigationControlleralloc]initWithRootViewController:fourth];

    NSArray * nsa =[[NSArrayalloc]initWithObjects:nav1,nav2,nav3,nav4,nil];

    _tabBarController.viewControllers=nsa;

    self.window.rootViewController=_tabBarController;

    

    [first release];

    [second release];

    [third release];

    [fourth release];

    [nav1 release];

    [nav2 release];

    [nav3 release];

    [nav4 release];

    [nsa release];

    

    self.window.backgroundColor = [UIColorwhiteColor];

    [self.windowmakeKeyAndVisible];

    return YES;

}

- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController

{

   

}

添加以下的代码,就可以实现上述功能了,小弟是ios初学者,可能有些地方描述不准确,代码书写不规范,希望各位大牛勿喷,同时希望给予指导和帮助。

写这篇博客就是自己的一个随身笔记,希望对各位有所帮助。

原创粉丝点击