Navigation学习笔记

时间:2023-03-09 18:35:16
Navigation学习笔记

***************************** 使用storyboard导航*********************************

storyboard方式相对简单。

Navigation学习笔记

在弹出来的选择框里选择跳转方式:

Navigation学习笔记

连接完成:

Navigation学习笔记

************************** 使用presentViewController导航 *************************

 // 建立一个继承自UIviewController的类secondViewController后

 secondViewController *second = [self.storyboard instantiateViewControllerWithIdentifier:@"// 写second这个viewController的storyboard属性名称,在右边的编辑器里可以编辑"]

 presentViewController:(UIViewController *) animated:(BOOL) completion:^(void)completion
 // 显示viewController

 // 也可以建立带xib的类,然后用
 initWithNibName:(NSString *) bundle:(NSBundle *)
 如:ThirdViewController *t = [[ThirdViewController alloc]initWithNibName:@"ThirdViewController" bundle:nil]

 // 然后再调用presentViewController方法

***************************** 使用UINavigationController导航 *************************

NavigationController使用栈结构。

NavigationControllerbar:比如新浪微博底部的导航条

看到 NavigationControlleritem :可以想到应该是一些自定义的东西

1. 首先在Supporting Files里的info.plist里将Main storyboard file base name对应的Main清除

Navigation学习笔记

2. 建立几个继承自UIViewController的类作为跳转资源

3. 在AppDelegate.m创建UIWindow实例,UIViewController实例,初始化根控制器

// AppDelegate.m

#import <AppDelegate.h>
#import "MyViewController1"
#import "MyViewController2"
#import "MyViewController3"
#import "MyViewController4"

@interface AppDelegate()

@end

@implementation AppDelegate

- (BOOL)applocation:(UIApplication *)application didLaunchingWithOptions:(NSDictionary *)launchOptions{
    UIScreen *screen = [UIScreen mainScreen];   // 得到当前屏幕大小

    self.window = [[UIWindow alloc]initWithFrame:screen.bounds];

    MyViewController1 *vc1 = [[MyViewController alloc]init];

    vc1.view.backgroundColor = [UIColor blueColor]; // 设置背景色

    UINavigationController *nc = [[UINavigation alloc]initWithRootViewController:];   //  实例化NavigationController

    self.window.rootViewController =nc;  // 使窗口根控制器为UINavigationController实例nc

    [self.window makeKeyAndVisible];   // 使窗口可见

    return YES;

@end