根据nib名称可以实现根据配置文件实例化UIViewController,也可以使用instantiateViewControllerWithIdentifier方法从Storyboard实例化UIViewController
UIViewController *vc;
//判断nib是否存在,如果存在,就加载
if ([[NSBundle mainBundle] pathForResource:destination ofType:@"nib"] != nil) {
vc = [[UIViewController alloc] initWithNibName:destination bundle:nil];
} else {
//从Storyboard实例化ViewController
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
vc = [sb instantiateViewControllerWithIdentifier:destination];
}
[self.navigationController pushViewController:vc animated:YES];
//判断nib是否存在,如果存在,就加载
if ([[NSBundle mainBundle] pathForResource:destination ofType:@"nib"] != nil) {
vc = [[UIViewController alloc] initWithNibName:destination bundle:nil];
} else {
//从Storyboard实例化ViewController
UIStoryboard *sb = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
vc = [sb instantiateViewControllerWithIdentifier:destination];
}
[self.navigationController pushViewController:vc animated:YES];