日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UITabbarController 实例一

發布時間:2024/4/15 编程问答 54 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UITabbarController 实例一 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

今天用純代碼來實現UITabbarController的功能,不需要在xib里面使用任何控件?

本文轉自?http://www.999dh.net/article/iphone_ios_art/47.html? 轉載請注明謝謝!
1.建立一個 empty application 工程
2.在 appdelegate.h文件里面實現如下

@interface XYZAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (retain,nonatomic) UITabBarController * tabController;

@end


3.定義3個 viewController?? 繼承自??UIViewController??名字分別為 FirstViewController,SecondViewController,ThirdViewController ,然后分別在 每個view對應的xib文件里面拖上不同的控件(這樣做的目的是為了區分在tab 切換的時候已經切換到了不同的view上去)

4.appdeletate.m文件里面實現如下


#import "XYZAppDelegate.h"
#import "FirstViewController.h"
#import "SecondViewController.h"
#import "ThirdViewController.h"

@implementation XYZAppDelegate

@synthesize window = _window;
@synthesize tabController;

- (void)dealloc
{
????[_window release];
????[super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
????self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
????// Override point for customization after application launch.
????self.window.backgroundColor = [UIColor whiteColor];
????
????
????FirstViewController * fristView = [[FirstViewController alloc] init];
????SecondViewController* secView = [[SecondViewController alloc] init];
????ThirdViewController * thirdView = [[ThirdViewController alloc] init];
????UITableViewController * forthView = [[UITableViewController alloc] init];
????
????NSArray * array = [[NSArray alloc]initWithObjects:fristView,secView,thirdView, forthView,nil];
????
????tabController = [[UITabBarController alloc]init];
????
????tabController.viewControllers = array;
????
????[[tabController.tabBar.items objectAtIndex:0]setTitle:@"AAA"];
????[[tabController.tabBar.items objectAtIndex:1]setTitle:@"BBBB"];
????[[tabController.tabBar.items objectAtIndex:2]setTitle:@"CCCC"];
????[[tabController.tabBar.items objectAtIndex:3]setTitle:@"DDDD"];
????
????[[tabController.tabBar.items objectAtIndex:0]setImage:[UIImage imageNamed:@"001.png"]];
????[[tabController.tabBar.items objectAtIndex:1]setImage:[UIImage imageNamed:@"002.png"]];
????[[tabController.tabBar.items objectAtIndex:2]setImage:[UIImage imageNamed:@"003.png"]];
????[[tabController.tabBar.items objectAtIndex:3]setImage:[UIImage imageNamed:@"004.png"]];
????
????tabController.selectedIndex = 1;
????
????[self.window addSubview:tabController.view];
????
????
????[array release];
????
????
????[self.window makeKeyAndVisible];
????return YES;
}


實現后的效果如圖所示??

轉載于:https://www.cnblogs.com/rollrock/archive/2013/01/04/2843756.html

超強干貨來襲 云風專訪:近40年碼齡,通宵達旦的技術人生

總結

以上是生活随笔為你收集整理的UITabbarController 实例一的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。