mirror of
https://github.com/cappuccino/cappuccino.git
synced 2026-09-07 19:27:12 +00:00
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.
This commit is contained in:
@@ -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];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user