iOS中xib与storyboard各种加载
xib 加载自定义View
UIView *view = [[NSBundle mainBundle] loadNibNamed:@"MyView" owner:self options:nil][0];
xib 加载自定义控制器
UIViewController *vc = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
storyboard 加载自定义控制器
UIStoryboard*storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil]; UIViewController*vc = [storyboard instantiateInitialViewController];
UIStoryboard *storyBoard = [UIStoryboard storyboardWithName:@"HomeViewController" bundle:nil]; HomeViewController *homeVC = [storyBoard instantiateViewControllerWithIdentifier:@"HomeViewController"]; HomeNavigationController *nav1 = [[HomeNavigationController alloc] initWithRootViewController:homeVC]; nav1.tabBarItem.title = @"主页";
xib 加载自定义cell
//第一步在控制器生命周期中注册 [self.msgTableView registerNib:[UINib nibWithNibName:@"RTJFMyMsgTableViewCell" bundle:nil] forCellReuseIdentifier:cellID]; //第二步在表格数据源代理中返回 RTJFMyMsgTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID]; if (cell == nil) { cell = [[RTJFMyMsgTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID]; } return cell;