对于一些自定义的控件来说,如果在控件.m文件里面写关于他的父视图(self.superview)的,一定要这个控件初始化完成之后才能够再做关于self.superview的一些事情。所以关于self.superview的事情不能写在init方法里面。只能写在init的外面的方法。
self.ttvc=[[TTViewController alloc]init];
self.ttvc.view.frame=CGRectMake(0, 0, 100, 100);
self.ttvc.view.backgroundColor=[UIColor redColor];
[self.superview addSubview:self.ttvc.view];