我的视图层次结构位于几个自定义“根” UIViewController 子类上。我正在尝试为我的根 VC 子类之一设置自定义 self.view。在那里,我正在做:
MyRootViewController_With_Scroll.h
// Import lowest level root VC
#import "MyRootViewController.h"
// my custom scroll view I want to use as self.view
@class MyScrollView;
@interface MyRootViewController_With_Scroll : MyRootViewController {
}
@property (strong) MyScrollView *view;
@end
MyRootViewController_With_Scroll.m
#import MyRootViewController_With_Scroll.h;
@interface MyRootViewController_With_Scroll ()
@end
@implementation MyRootViewController_With_Scroll
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)loadView
{
NSLog(@"loading view");
CGRect windowSize = [UIScreen mainScreen].applicationFrame;
MyScrollView *rootScrollView = [MyScrollView scrollerWithSize:windowSize.size];
self.view = rootScrollView;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
// Getter and setter for self.view
- (MyScrollView *)view
{
return (MyScrollView *)[super view];
}
- (void)setView:(MyScrollView *)view
{
[super setView:view];
}
根据 iOS6 文档,viewDidLoad 在应用程序的整个生命周期中只假设每个视图控制器触发一次。
我在这里做错了什么?是什么导致我的视图控制器反复调用 loadView/viewDidLoad?奇怪的是,我的应用程序“主屏幕”VC 只加载一次视图,但导航层级中的所有后续视图每次出现时都会触发 loadView。到底是怎么回事?
编辑我已将属性更改为strong
. 发生同样的问题。
编辑 2我已经停止覆盖 loadView 并且它仍在发生。现在我真的很困惑。