在运行时加载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];
}
//导入创建的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];
}
相关文章推荐
- Struts Hello World Example
- jquery $(document).ready() 与window.onload的区别
- EJB简介
- UMCrashAnalyze总结
- 调用百度地图接口获取地理位置手机电脑通用
- JS日期的获取与加减
- java学习中易忽略的知识
- PPT控电脑端怎么样
- android adapter的notifyDataSetChanged不起作用
- POJ 2579 && HDU 1218 Blurred Vision(水~)
- 日经社説 20150828 薬局の機能を高め医療の効率化進めよ
- UVA10976 Fractions Again?!
- 【排序算法】插入排序
- C# Winform简单绘图 (在直角坐标系中画折线)
- 日经春秋 20150828
- 地理编码(根据地址得出位置并且加上自定义的大头针)
- JAVA环境变量配置备忘
- 安卓解析 json 4种格式 全解析
- 初学Oracle UNPIVOT,PIVOT,WMSYS.WM_CONCAT三个函数
- spark官方文档翻译收藏