iOS displays the second page

0. Create a project and select Single View App

1. Select the item, New File...

Select View, Next, Create, and a xib file will appear

2. Create new View2Controller.m and View2Controller.h files and add content

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

@interface View2Controller : UIViewController


@end
//View2Controller.m

#import "View2Controller.h"


@implementation View2Controller

    

@end

3. Set the controller class of the xib file, select the xib file, and write View2Controller in the class

 

4. Associate File's Owner and view interface, drag + to the interface

 

5. In the other ViewController class that wants to open the second page, implement the event of the button control

- (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. Close the code of the second page and implement it on the second page


#import "View2Controller.h"


@implementation View2Controller

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


@end

 

Guess you like

Origin blog.csdn.net/m0_37981386/article/details/106791852