如果你想做一个类似于满座的下面的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 = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
_tabBarController=[[UITabBarController alloc]init];
_tabBarController.delegate=self;
MainViewController*first=[[MainViewController alloc]init];
first.tabBarItem.title=@"主页";
first.tabBarItem.image=[UIImage imageNamed:@"a.png"];
NearViewController *second=[[NearViewController alloc]init];
second.tabBarItem.title=@"周边";
second.tabBarItem.image=[UIImage imageNamed:@"c.png"];
SearchViewController*third=[[SearchViewController alloc]init];
third.tabBarItem.title=@"搜索";
third.tabBarItem.image=[UIImage imageNamed:@"e.png"];
AppSetingViewController*fourth=[[AppSetingViewController alloc]init];
fourth.tabBarItem.title=@"满座";
fourth.tabBarItem.image=[UIImage imageNamed:@"s.png"];
UINavigationController * nav1 =[[UINavigationController alloc]initWithRootViewController:first];
UINavigationController * nav2 =[[UINavigationController alloc]initWithRootViewController:second];
UINavigationController * nav3 =[[UINavigationController alloc]initWithRootViewController:third];
UINavigationController * nav4 =[[UINavigationController alloc]initWithRootViewController:fourth];
NSArray * nsa =[[NSArray alloc]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 = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController
{
}
添加以下的代码,就可以实现上述功能了,小弟是ios初学者,可能有些地方描述不准确,代码书写不规范,希望各位大牛勿喷,同时希望给予指导和帮助。
写这篇博客就是自己的一个随身笔记,希望对各位有所帮助。