
##sinitWithFrame 和 initWithCoder
当我们所写的程序里没用用Nib文件(XIB)时,用代码控制视图内容,需要调用initWithFrame去初始化
1 |
- (id)initWithFrame:(CGRect)frame |
用于视图加载nib文件,从nib中加载对象实例时,使用 initWithCoder初始化这些实例对象
1 |
- (id)initWithCoder:(NSCoder*)coder |
Assuming you have storyboard, go to storyboard and give your VC an identifier (inspector), then do:
1 |
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil]; UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"IDENTIFIER"]; [self.navigationController pushViewController:vc animated:YES]; |
Assuming you have a xib file you want to do:
1 |
UIViewController *vc = [[UIViewController alloc] initWithNibName:@"NIBNAME" bundle:nil]; [self.navigationController pushViewController:vc animated:YES]; |
Without a xib file:
1 |
UIViewController *vc = [[UIViewController alloc] init]; [self.navigationController pushViewController:vc animated:YES]; |
从xib中加载UIview
1 |
NSArray *niblets = [[NSBundle mainBundle] loadNibNamed:@"sample" owner:self options:NULL]; |




近期评论