美文网首页基础应用GXiOS
iOS中xib与storyboard各种加载

iOS中xib与storyboard各种加载

作者: _Jock羁 | 来源:发表于2016-08-10 14:37 被阅读1427次
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];
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;

相关文章

网友评论

    本文标题:iOS中xib与storyboard各种加载

    本文链接:https://www.haomeiwen.com/subject/tahjsttx.html