iOS 显示第二个页面

0、 创建一个工程,选择 Single View App

1 、选中项目,New File...

选中View, Next,Create ,会出现一个 xib文件

2、 新建 View2Controller.m和 View2Controller.h文件,添加内容

//View2Controller.h
#import <UIKit/UIKit.h>

@interface View2Controller : UIViewController


@end
//View2Controller.m

#import "View2Controller.h"


@implementation View2Controller

    

@end

3、 设置  xib文件的控制器类,选中 xib文件,在class中 写入 View2Controller

4、关联 File‘s Owner和view界面,拖动 + 到界面

扫描二维码关注公众号,回复: 12755670 查看本文章

5、 在其他要打开第二页的ViewController 类,实现按钮控件的事件

- (IBAction)OnChangePageEvent:(id)sender {
    
    //initWithNibName后+xib文件名
     View2Controller *vc2=[[View2Controller alloc]initWithNibName:@"View2" bundle:nil];
    //设置页面的出现方式
    vc2.modalPresentationStyle= UIModalPresentationOverCurrentContext;
     //呈现出vc2
     [self presentViewController:vc2 animated:YES completion:^{
     }];
    
}


6、关闭第二页的代码,在第二个页面实现


#import "View2Controller.h"


@implementation View2Controller

- (IBAction)OnBackFirstPage:(id)sender {
    
    [self dismissViewControllerAnimated:YES completion:^{
          NSLog(@"%s","关闭第二页");
     }];
}


@end

猜你喜欢

转载自blog.csdn.net/m0_37981386/article/details/106791852