您的位置:首页 > 产品设计 > UI/UE

ios学习之 初识UINavigationController

2015-07-21 13:57 375 查看
今天学习了UINavigationController,在这里总结一下使用方法

NS_CLASS_AVAILABLE_IOS(2_0) @interface UINavigationController : UIViewController


UINavigationController继承自UIViewController,在其基础上封装了头部导航



下面来看看如何使用UINavigationController,首先在AppDelegate.h中添加属性,如下:

#import <UIKit/UIKit.h>
#import "ViewController.h"

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@property (strong,nonatomic) ViewController *vc;//需要显示的ViewController
@property (strong,nonatomic) UINavigationController *navController;//声明一个UINavigationController

@end


然后将UINavigationController加入到window中,再将需要展示的UIViewController加入到UINavigationController中

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
self.window=[[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];

//初始化要显示的ViewController
self.vc=[[ViewController alloc]init];

//先初始化UINavigationController,再将vc加入UINavigationController,再把UINavigationController加入到window中,以下两种方式都可以实现
//1
self.navController=[[UINavigationController alloc]init];
[self.navController pushViewController:self.
vc animated:true];
[self.window addSubview:self.navController.view];
//2
self.window.rootViewController=[[UINavigationController alloc]initWithRootViewController:self.vc];
[self.window makeKeyAndVisible];
return YES;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: