您的位置:首页 > 其它

在运行时加载XIB文件

2015-08-28 09:38 387 查看
先创建一个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];
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: