先创建一个RuntimeViewController,并且绑定xib,直接上代码:
//导入创建的xib文件
#import "RuntimeViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
//创建一个按钮
UIButton *myBtn=[[UIButton alloc]initWithFrame:CGRectMake(100, 200, 100, 44)];
//在按钮上面设置文字
[myBtn setTitle:@"加载" forState:UIControlStateNormal];
//为按钮绑定一个点击事件
[myBtn addTarget:self action:@selector(loadXib) forControlEvents:UIControlEventTouchUpInside];
//把按钮添加到视图上面
[self.view addSubview:myBtn];
// Do any additional setup after loading the view, typically from a nib.
}
-(void)loadXib{
//创建对象
RuntimeViewController *rtVC=[[RuntimeViewController alloc]initWithNibName:@"RuntimeViewController" bundle:nil];
//页面跳转
[self presentViewController:rtVC animated:YES completion:nil];
}