Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2604475
  • 博文数量: 877
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 5920
  • 用 户 组: 普通用户
  • 注册时间: 2013-12-05 12:25
个人简介

技术的乐趣在于分享,欢迎多多交流,多多沟通。

文章分类

全部博文(877)

文章存档

2021年(2)

2016年(20)

2015年(471)

2014年(358)

2013年(26)

分类: iOS平台

2015-10-25 15:34:28

定义一个新的CustomView继承自UIView,在Xib文件的View里面设置其Custom Class为 CustomView.m 然后 初始化

    CustomView *customView = [[[NSBundle mainBundle] loadNibNamed:@"CustomView" owner:self options:nil] lastObject];

//    CustomView *customView = [CustomView shareCustomView];

    [self.view addSubview:customView];

这样 以下两个函数就被调用了

在UIViewController里面创建的XIB文件不会调用 initWithCoder,但会调用

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

初始化时使用:

    CustomViewController *customVC = [[CustomViewController alloc] initWithNibName:@"CustomViewController" bundle:nil];

    CustomViewController *customVC = [[CustomViewController alloc] init];

    [self presentViewController:customVC animated:YES completion:nil];


- (void)awakeFromNib


{

    NSLog(@"CustomView44444444");

}

- (instancetype)initWithCoder:(NSCoder *)aDecoder

{

    self = [super initWithCoder:aDecoder];

    if (self) {

        NSLog(@"CustomView");

    }

    return self;

}

阅读(615) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~