Skip to content
This repository has been archived by the owner on Jun 8, 2023. It is now read-only.

Controller/View life cycle fix. #85

Merged
merged 6 commits into from
Jul 5, 2013
Merged
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion Rebel/RBLViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,21 @@ @interface RBLViewController ()

@end

@implementation RBLViewController
@implementation RBLViewController {
__weak NSView *_currentView;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you change this to a property, and make it strong? The view controller owns its view, so it's okay to have a strong reference in this case.

}

+(id)viewController
{
return [[self alloc] initWithNibName:NSStringFromClass([self class]) bundle:nil];
}

-(void)dealloc {
if (self.view.rbl_viewController == self) {
self.view.rbl_viewController = nil;
}
}

-(void)loadView
{
[super loadView];
Expand All @@ -30,6 +38,11 @@ -(void)setView:(NSView *)view
{
super.view = view;
self.view.rbl_viewController = self;

if (_currentView.rbl_viewController == self) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling self.view before super.view = view would cause an infinit loop.

self.view accessor instantiates loadView or the nib and ends up calling setView.

Hmm, very true, but this seems hacky. I don't think I have a better solution right now, though.

_currentView.rbl_viewController = nil;
}
_currentView = view;
}

- (void)viewDidLoad
Expand Down