From 677cb4638f842e62b3eda2ac024fdc4150840226 Mon Sep 17 00:00:00 2001 From: Klaas Pieter Annema Date: Tue, 14 Sep 2010 12:58:47 +0200 Subject: [PATCH] fix bug where CPViewController viewDidLoad is called to early The bug was caused by connections (outlets) being defined in undefined order. Sometimes the view connection was decoded and connected before other connections, because setView: would automatically call viewDidLoad the first time a view was set viewDidLoad was called before the entire view was actually loaded. ViewDidLoad is now only called from setView: if the _view === nil and no view is currently being loaded. --- AppKit/CPViewController.j | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/AppKit/CPViewController.j b/AppKit/CPViewController.j index 9d31db0f0..b5c18de9f 100644 --- a/AppKit/CPViewController.j +++ b/AppKit/CPViewController.j @@ -47,7 +47,8 @@ var CPViewControllerCachedCibs; */ @implementation CPViewController : CPResponder { - CPView _view; + CPView _view @accessors(property=view); + BOOL _isLoading; id _representedObject @accessors(property=representedObject); CPString _title @accessors(property=title); @@ -99,6 +100,8 @@ var CPViewControllerCachedCibs; _cibName = aCibNameOrNil; _cibBundle = aCibBundleOrNil || [CPBundle mainBundle]; _cibExternalNameTable = anExternalNameTable || [CPDictionary dictionaryWithObject:self forKey:CPCibOwner]; + + _isLoading = NO; } return self; @@ -120,7 +123,7 @@ var CPViewControllerCachedCibs; { if (_view) return; - + // check if a cib is already cached for the current _cibName var cib = [CPViewControllerCachedCibs objectForKey:_cibName]; @@ -143,6 +146,8 @@ var CPViewControllerCachedCibs; { if (!_view) { + _isLoading = YES; + var cibOwner = [_cibExternalNameTable objectForKey:CPCibOwner]; if ([cibOwner respondsToSelector:@selector(viewControllerWillLoadCib:)]) @@ -162,6 +167,9 @@ var CPViewControllerCachedCibs; if ([cibOwner respondsToSelector:@selector(viewControllerDidLoadCib:)]) [cibOwner viewControllerDidLoadCib:self]; + + _isLoading = NO; + [self viewDidLoad]; } return _view; @@ -192,7 +200,7 @@ var CPViewControllerCachedCibs; _view = aView; // Make sure the viewDidLoad method is called if the view is set directly - if (viewWasLoaded) + if (!_isLoading && viewWasLoaded) [self viewDidLoad]; }