WEB开发网
开发学院手机开发iPhone 开发 IOS控件列表UITabBarController 阅读

IOS控件列表UITabBarController

 2012-09-10 17:54:38 来源:WEB开发网   
核心提示://每个UIController中都有一个navigationItem和一个tabBarItem 一般创建一个相应类型的对象 对其赋值//系统样式UITabBarItem * barItem1 = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystem

//每个UIController中都有一个navigationItem和一个tabBarItem 一般创建一个相应类型的对象 对其赋值
//系统样式
UITabBarItem * barItem1 = [[UITabBarItem alloc]initWithTabBarSystemItem:UITabBarSystemItemContacts tag:0];
barItem1.badgeValue = @"1";
yvCtrl.tabBarItem = barItem1;
//自定义样式
firstController.tabBarItem=[[UITabBarItem alloc] initWithTitle:@"First" image:[UIImage imageNamed:@"img.png"] tag:101]

//重写ViewController里的init 在初始化里添加Item
(id)init {
if ([super init] != nil) {
UITabBarItem *item = [[UITabBarItem alloc] initWithTitle:@"asdfsadf" image:[UIImage imageNamed:@"WWAN5.png"] tag:1];
self.tabBarItem = item;
[item release];
}
return self;
}


创建一个UITabConroller:

.h文件中:

#import<UIKit/UIKit.h>

@interface AppDelegate :UIResponder <UIApplicationDelegate,UITabBarControllerDelegate>
{
    UITabBarController*     tabBarController;
}

@property (strong,nonatomic)UIWindow *window;
@property (nonatomic,retain) UITabBarController*     tabBarController;
-(void) initTabBarController;

@end

.m文件中:

-(void) initTabBarController
{
   // create a tab bar controller
   self.tabBarController = [[UITabBarControlleralloc]init];
    self.tabBarController.delegate =self;
   //1====>navhomeController
    HomeController* homeView = [[HomeControlleralloc]initWithNibName :@"HomeController"bundle : nil];
    UINavigationController* navhomeController = [[UINavigationControlleralloc]initWithRootViewController : homeView];
    [homeView release];
    [navhomeController.navigationBarcustomed];
    [navhomeController.navigationBarcustomedBarBackground];
    navhomeController.navigationBar.topItem.title =@"文件查看";
    navhomeController.tabBarItem = [[UITabBarItemalloc]initWithTitle:@"文件查看" image:[UIImageimageNamed:@"home.png"] tag :0];
    
   TempViewController* temp1 = [[TempViewControlleralloc]initWithNibName:@"TempViewController"bundle:nil];
   UINavigationController* navTempController = [[UINavigationControlleralloc]initWithRootViewController : temp1];
    [temp1 release];
    navTempController.navigationBar.topItem.title =@"最近";
    navTempController.tabBarItem = [[UITabBarItemalloc]initWithTitle:@"最近"image:[UIImageimageNamed:@"icon_bookmark.png"] tag :1];
    
   DesktopViewController* desktopView = [[DesktopViewControlleralloc]initWithNibName:@"DesktopViewController"bundle:nil];
    UINavigationController* navDesktopView = [[UINavigationControlleralloc]initWithRootViewController : desktopView];
    [desktopView release];
    [navDesktopView.navigationBarcustomed];
    navDesktopView.navigationBar.topItem.title =@"桌面";
    navDesktopView.tabBarItem = [[UITabBarItemalloc]initWithTitle:@"桌面"image:[UIImageimageNamed:@"icon_attention.png"] tag :2];
    
   TempViewController* temp3 = [[TempViewControlleralloc]initWithNibName:@"TempViewController"bundle:nil];
   UINavigationController* navTempController3 = [[UINavigationControlleralloc]initWithRootViewController : temp3];
    [temp3 release];
    navTempController3.navigationBar.topItem.title =@"搜索";
    navTempController3.tabBarItem = [[UITabBarItemalloc]initWithTitle:@"搜索"image:[UIImageimageNamed:@"icon_search.png"] tag :3];
    
    
   //5====>SettingController
    SettingController* settingView = [[SettingControlleralloc]initWithNibName :@"SettingController"bundle : nil];
    UINavigationController* navSettingView = [[UINavigationControlleralloc]initWithRootViewController : settingView];
    [settingView release];
    navSettingView.navigationBar.topItem.title =@"设置";
    navSettingView.tabBarItem = [[UITabBarItemalloc]initWithTitle:@"设置"image:[UIImageimageNamed:@"icon_setting.png"] tag :4];
    
    tabBarController.viewControllers = [NSArrayarrayWithObjects : navhomeController,navTempController,navDesktopView,navTempController3,navSettingView,nil];
    
    OCRELEASE(navhomeController);
    OCRELEASE(navTempController);
    OCRELEASE(navDesktopView);
    OCRELEASE(navTempController3);
    OCRELEASE(navSettingView);
    
   // add navigation controllers to the tab bar controller
   //    tabBarController.viewControllers = [NSArray arrayWithObjects : navhomeController,navPersonalController,navAttentionView,navSeekView,navSettingView,nil];
   //    OCRELEASE(navhomeController);
   //    OCRELEASE(navPersonalController);
   //    OCRELEASE(navAttentionView);
   //    OCRELEASE(navSeekView);
   //    OCRELEASE(navSettingView);
}
@synthesize tabBarController;

- (void)dealloc
{
    [_windowrelease];
    [tabBarControllerrelease];
    [superdealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
   self.window = [[[UIWindowalloc]initWithFrame:[[UIScreenmainScreen]bounds]]autorelease];
   // Override point for customization after application launch.
    [selfinitTabBarController];
    
   self.window.rootViewController =tabBarController;
    [self.windowmakeKeyAndVisible];
   returnYES;
}

上一页  1 2 

Tags:IOS 控件 列表

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接