如题,添加addChildViewController子viewController仍然无响应- (void)viewDidLoad {
[super viewDidLoad]; // Do any additional setup after loading the view.
UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(50, 200, 60, 60)];
[btn setTitle:@"点我" forState:UIControlStateNormal];
[btn addTarget:self action:@selector(btnClick) forControlEvents:UIControlEventTouchUpInside];
[btn setBackgroundColor:[UIColor blackColor]];
[self.view addSubview:btn];
[self addChildViewController:self.imgVC];
}
- (void)btnClick{ NSLog(@"点击了按钮");
}// 懒加载- (addImgVC *)imgVC{ if (!_imgVC) {
_imgVC = [[addImgVC alloc]init];
[_imgVC.view setFrame:CGRectMake(0, 50, 375, 62)];
[self.view addSubview:_imgVC.view];
} return _imgVC;
}
1 回答
慕虎7371278
TA贡献1802条经验 获得超4个赞
你的调用流程还是没弄清楚,把你的[self.view addSubview:self.imgVC.view]
写在addChildViewController
就可以了。因为你懒加载的时候,你写的流程是先添加了view
,然后再添加子控制器,然而正确的流程是先添加子控制器,然后才能添加view
- 1 回答
- 0 关注
- 609 浏览
添加回答
举报
0/150
提交
取消