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

Commit

Permalink
Merge pull request #6 from jmig/kvo-fix
Browse files Browse the repository at this point in the history
KVO Fixing, Updated .gitignore
  • Loading branch information
bdbergeron committed Jan 3, 2014
2 parents d2913ea + 2d75deb commit 69d7f54
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 6 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# OS X
.DS_Store

# Xcode
build/
*.pbxuser
!default.pbxuser
*.mode1v3
!default.mode1v3
*.mode2v3
!default.mode2v3
*.perspectivev3
!default.perspectivev3
xcuserdata
*.xccheckout
profile
*.moved-aside
DerivedData
*.hmap
*.ipa

# CocoaPods
Pods
21 changes: 15 additions & 6 deletions BDBSplitViewController/BDBSplitViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ - (id)initWithMasterViewController:(UIViewController *)mvc detailViewController:
return self;
}

- (void)dealloc
{
//Remove the observer to avoid KVO informations leakage error (NSKVODeallocateBreak)
[self.detailViewController removeObserver:self forKeyPath:@"view.frame" context:kBDBSplitViewKVOContext];
}

- (void)awakeFromNib
{
[super awakeFromNib];
Expand Down Expand Up @@ -139,13 +145,16 @@ - (void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrie

- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([object isEqual:self.detailViewController] && [keyPath isEqualToString:@"view.frame"])
if (context == kBDBSplitViewKVOContext)
{
UIView *view = self.detailViewController.view;
CGRect currentFrame = [change[@"new"] CGRectValue];
CGRect properFrame = [self detailViewFrameForState:self.masterViewState];
if (!CGRectEqualToRect(currentFrame, properFrame))
view.frame = [self detailViewFrameForState:self.masterViewState];
if ([object isEqual:self.detailViewController] && [keyPath isEqualToString:@"view.frame"])
{
UIView *view = self.detailViewController.view;
CGRect currentFrame = [change[@"new"] CGRectValue];
CGRect properFrame = [self detailViewFrameForState:self.masterViewState];
if (!CGRectEqualToRect(currentFrame, properFrame))
view.frame = [self detailViewFrameForState:self.masterViewState];
}
}
else
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
Expand Down

0 comments on commit 69d7f54

Please sign in to comment.