- (void)viewDidLoad {
[super viewDidLoad];
//请解释死循环
// self.view = nil;
// NSLog(@"%@",self.view);
}
- (UIView *)view{
//如果view存在。则返回
if ([self valueForKey:@"_view"]) {
return [self valueForKey:@"_view"];
}
//如果不存在,先调用loadView再调用viewDidLoad
[self loadView];
[self viewDidLoad];
return [self valueForKey:@"_view"];
}
- (void)loadView{
//判断xib是否存在
NSFileManager*manage =[NSFileManager defaultManager];
NSString *path =[[[NSBundle mainBundle]bundlePath]stringByAppendingFormat:@"/%@.nib",NSStringFromClass([self class])];
if ([manage fileExistsAtPath:path]) {
//通过加载xib文件加载视图
[[NSBundle mainBundle]loadNibNamed:NSStringFromClass([self class]) owner:self options:nil];
return;
}
//如果不存在xib文件,则初始化一个白的视图
UIView *v = [[UIView alloc] initWithFrame:[UIScreen mainScreen].bounds];
v.backgroundColor = [UIColor redColor];
[self setView:v];
}
在TextViewController中得nib中画两个view;是并列的view
在viewController中push一个页面。