iOS,视图控制器相关(UIViewController)
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了iOS,视图控制器相关(UIViewController)相关的知识,希望对你有一定的参考价值。
2.选项卡(Tab Bar)和导航栏(Navigation Bar)
init:方法
选项卡(Tab Bar)和导航栏(Navigation Bar)
//AppDelegate.h文件
#import <UIKit/UIKit.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow *window;
@property(strong,nonatomic) UITabBarController *tabBarController;//底部选项卡控制器
@end
//AppDelegate.m文件
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
//消息控制器
MessageViewController *msgController=[[MessageViewController alloc] init];
UINavigationController *navMsg=[[UINavigationController alloc] initWithRootViewController:msgController];
//选项卡的图片样式以这种方式处理,避免图片无法完全显示
UITabBarItem *msgTabItem = [[UITabBarItem alloc]initWithTitle:@"消息" image:[[UIImage imageNamed:@"[email protected]"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"[email protected]"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
navMsg.tabBarItem=msgTabItem;
//联系人控制器
ContactViewController *conController=[[ContactViewController alloc] init];
UINavigationController *navCon=[[UINavigationController alloc] initWithRootViewController:conController];
UITabBarItem *conTabItem = [[UITabBarItem alloc]initWithTitle:@"联系人" image:[[UIImage imageNamed:@"tab_ [email protected]"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"tab_ [email protected]"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
navCon.tabBarItem=conTabItem;
//动态控制器
DynamicViewController *dynController=[[DynamicViewController alloc] init];
UINavigationController *navDyn=[[UINavigationController alloc] initWithRootViewController:dynController];
UITabBarItem *dynTabItem = [[UITabBarItem alloc]initWithTitle:@"动态" image:[[UIImage imageNamed:@"tab_ [email protected]"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] selectedImage:[[UIImage imageNamed:@"tab_ [email protected]"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
navDyn.tabBarItem=dynTabItem;
self.tabBarController=[[UITabBarController alloc] init];
[email protected][navMsg,navCon,navDyn];
self.tabBarController.selectedIndex=0;
//由于iPhone是单窗口程序,所以也就只有这么一个Window对象,而且是UIWindow,不是NSWindow。而根据文档上所说:这个是便捷方法,去使被使用对象的主窗口显示到屏幕的最前端。
[self.window makeKeyAndVisible];
return YES;
}
以上是关于iOS,视图控制器相关(UIViewController)的主要内容,如果未能解决你的问题,请参考以下文章
如何在 UITabBarController 中加载所有视图?
没有情节提要的 UIViewController 状态恢复不起作用