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

Commit

Permalink
Fixed EXEC_BAD_ACCESS crash when setting the detailViewController.
Browse files Browse the repository at this point in the history
Also added other detail view controllers to demo each of the available presentation styles.
  • Loading branch information
Bradley Bergeron authored and Bradley Bergeron committed Nov 4, 2013
1 parent 379c0cf commit 4bb646d
Show file tree
Hide file tree
Showing 13 changed files with 517 additions and 42 deletions.
24 changes: 15 additions & 9 deletions BDBSplitViewController/BDBSplitViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
} BDBMasterViewState;


static void * const kBDBSplitViewKVOContext = (void*)&kBDBSplitViewKVOContext;


#pragma mark -
@interface BDBSplitViewController ()

Expand Down Expand Up @@ -67,11 +70,6 @@ - (id)initWithMasterViewController:(UIViewController *)mvc detailViewController:
}];
self.viewControllers = mutableViewControllers;
}

if ([dvc isKindOfClass:[BDBDetailViewController class]])
self.delegate = (BDBDetailViewController *)dvc;

[self.detailViewController addObserver:self forKeyPath:@"view.frame" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:nil];
}
return self;
}
Expand Down Expand Up @@ -204,17 +202,25 @@ - (void)setViewControllers:(NSArray *)viewControllers
{
NSAssert(viewControllers && viewControllers.count == 2, @"viewControllers must contain a master and a detail view controller.");

self.delegate = nil;
[self.detailViewController removeObserver:self forKeyPath:@"view.frame" context:kBDBSplitViewKVOContext];

[super setViewControllers:viewControllers];

[self.detailViewController addObserver:self forKeyPath:@"view.frame" options:NSKeyValueObservingOptionNew|NSKeyValueObservingOptionOld context:kBDBSplitViewKVOContext];

UIViewController *dvc = [(UINavigationController *)viewControllers[1] topViewController];
if ([dvc isKindOfClass:[BDBDetailViewController class]])
self.delegate = (BDBDetailViewController *)dvc;

[self configureMasterView];
}

#pragma mark Master / Detail Accessors
- (UIViewController *)masterViewController
{
if (self.viewControllers.count < 1)
return nil;
else
return self.viewControllers[0];
NSAssert(self.viewControllers.count > 0, @"self.viewControllers does not conatin a master view controller.");
return self.viewControllers[0];
}

- (UIViewController *)detailViewController
Expand Down
42 changes: 32 additions & 10 deletions SplitViewDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,13 @@
objects = {

/* Begin PBXBuildFile section */
E8660D65182851EA0024870C /* StickyDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E8E73A86181B5E7B00F8BC1D /* StickyDetailViewController.xib */; };
E8660D66182852010024870C /* StickyDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8C61F4518284FA200DBA379 /* StickyDetailViewController.m */; };
E8942F71181B60F500D8D423 /* SSSocialCircle.otf in Resources */ = {isa = PBXBuildFile; fileRef = E8942F6F181B60F500D8D423 /* SSSocialCircle.otf */; };
E8C61F4418284F8800DBA379 /* StickyDetailViewController.h in Resources */ = {isa = PBXBuildFile; fileRef = E8C61F4318284F8800DBA379 /* StickyDetailViewController.h */; };
E8C61F4818284FC600DBA379 /* NormalDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E8C61F4718284FC600DBA379 /* NormalDetailViewController.xib */; };
E8C61F4B1828507400DBA379 /* DrawerDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8C61F4A1828507400DBA379 /* DrawerDetailViewController.m */; };
E8C61F4D1828508400DBA379 /* DrawerDetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E8C61F4C1828508400DBA379 /* DrawerDetailViewController.xib */; };
E8D1B3C1181B179900D4A6BA /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8D1B3C0181B179900D4A6BA /* Foundation.framework */; };
E8D1B3C3181B179900D4A6BA /* CoreGraphics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8D1B3C2181B179900D4A6BA /* CoreGraphics.framework */; };
E8D1B3C5181B179900D4A6BA /* UIKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = E8D1B3C4181B179900D4A6BA /* UIKit.framework */; };
Expand All @@ -16,13 +22,18 @@
E8D1B3D1181B179900D4A6BA /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D1B3D0181B179900D4A6BA /* AppDelegate.m */; };
E8D1B3FE181B1E5400D4A6BA /* BDBSplitViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D1B3FD181B1E5400D4A6BA /* BDBSplitViewController.m */; };
E8D1B409181B236100D4A6BA /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = E8D1B400181B236100D4A6BA /* Images.xcassets */; };
E8D1B40B181B236100D4A6BA /* DetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D1B406181B236100D4A6BA /* DetailViewController.m */; };
E8D1B40B181B236100D4A6BA /* NormalDetailViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D1B406181B236100D4A6BA /* NormalDetailViewController.m */; };
E8D1B40C181B236100D4A6BA /* MasterViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = E8D1B408181B236100D4A6BA /* MasterViewController.m */; };
E8E73A87181B5E7B00F8BC1D /* DetailViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = E8E73A86181B5E7B00F8BC1D /* DetailViewController.xib */; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
E8942F6F181B60F500D8D423 /* SSSocialCircle.otf */ = {isa = PBXFileReference; lastKnownFileType = file; path = SSSocialCircle.otf; sourceTree = "<group>"; };
E8C61F4318284F8800DBA379 /* StickyDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StickyDetailViewController.h; sourceTree = "<group>"; };
E8C61F4518284FA200DBA379 /* StickyDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StickyDetailViewController.m; sourceTree = "<group>"; };
E8C61F4718284FC600DBA379 /* NormalDetailViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = NormalDetailViewController.xib; sourceTree = "<group>"; };
E8C61F491828506500DBA379 /* DrawerDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DrawerDetailViewController.h; sourceTree = "<group>"; };
E8C61F4A1828507400DBA379 /* DrawerDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DrawerDetailViewController.m; sourceTree = "<group>"; };
E8C61F4C1828508400DBA379 /* DrawerDetailViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DrawerDetailViewController.xib; sourceTree = "<group>"; };
E8D1B3BD181B179900D4A6BA /* SplitViewDemo.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = SplitViewDemo.app; sourceTree = BUILT_PRODUCTS_DIR; };
E8D1B3C0181B179900D4A6BA /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = System/Library/Frameworks/Foundation.framework; sourceTree = SDKROOT; };
E8D1B3C2181B179900D4A6BA /* CoreGraphics.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = CoreGraphics.framework; path = System/Library/Frameworks/CoreGraphics.framework; sourceTree = SDKROOT; };
Expand All @@ -36,11 +47,11 @@
E8D1B3FC181B1E5400D4A6BA /* BDBSplitViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = BDBSplitViewController.h; sourceTree = "<group>"; };
E8D1B3FD181B1E5400D4A6BA /* BDBSplitViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = BDBSplitViewController.m; sourceTree = "<group>"; };
E8D1B400181B236100D4A6BA /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = "<group>"; };
E8D1B405181B236100D4A6BA /* DetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = DetailViewController.h; sourceTree = "<group>"; };
E8D1B406181B236100D4A6BA /* DetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = DetailViewController.m; sourceTree = "<group>"; };
E8D1B405181B236100D4A6BA /* NormalDetailViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = NormalDetailViewController.h; sourceTree = "<group>"; };
E8D1B406181B236100D4A6BA /* NormalDetailViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = NormalDetailViewController.m; sourceTree = "<group>"; };
E8D1B407181B236100D4A6BA /* MasterViewController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MasterViewController.h; sourceTree = "<group>"; };
E8D1B408181B236100D4A6BA /* MasterViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MasterViewController.m; sourceTree = "<group>"; };
E8E73A86181B5E7B00F8BC1D /* DetailViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = DetailViewController.xib; sourceTree = "<group>"; };
E8E73A86181B5E7B00F8BC1D /* StickyDetailViewController.xib */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.xib; path = StickyDetailViewController.xib; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -137,11 +148,17 @@
E8D1B404181B236100D4A6BA /* View Controllers */ = {
isa = PBXGroup;
children = (
E8D1B405181B236100D4A6BA /* DetailViewController.h */,
E8D1B406181B236100D4A6BA /* DetailViewController.m */,
E8E73A86181B5E7B00F8BC1D /* DetailViewController.xib */,
E8D1B407181B236100D4A6BA /* MasterViewController.h */,
E8D1B408181B236100D4A6BA /* MasterViewController.m */,
E8D1B405181B236100D4A6BA /* NormalDetailViewController.h */,
E8D1B406181B236100D4A6BA /* NormalDetailViewController.m */,
E8C61F4718284FC600DBA379 /* NormalDetailViewController.xib */,
E8C61F4318284F8800DBA379 /* StickyDetailViewController.h */,
E8C61F4518284FA200DBA379 /* StickyDetailViewController.m */,
E8E73A86181B5E7B00F8BC1D /* StickyDetailViewController.xib */,
E8C61F491828506500DBA379 /* DrawerDetailViewController.h */,
E8C61F4A1828507400DBA379 /* DrawerDetailViewController.m */,
E8C61F4C1828508400DBA379 /* DrawerDetailViewController.xib */,
);
path = "View Controllers";
sourceTree = "<group>";
Expand Down Expand Up @@ -198,10 +215,13 @@
isa = PBXResourcesBuildPhase;
buildActionMask = 2147483647;
files = (
E8660D65182851EA0024870C /* StickyDetailViewController.xib in Resources */,
E8C61F4818284FC600DBA379 /* NormalDetailViewController.xib in Resources */,
E8942F71181B60F500D8D423 /* SSSocialCircle.otf in Resources */,
E8D1B3CB181B179900D4A6BA /* InfoPlist.strings in Resources */,
E8E73A87181B5E7B00F8BC1D /* DetailViewController.xib in Resources */,
E8D1B409181B236100D4A6BA /* Images.xcassets in Resources */,
E8C61F4418284F8800DBA379 /* StickyDetailViewController.h in Resources */,
E8C61F4D1828508400DBA379 /* DrawerDetailViewController.xib in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand All @@ -214,9 +234,11 @@
files = (
E8D1B3D1181B179900D4A6BA /* AppDelegate.m in Sources */,
E8D1B3FE181B1E5400D4A6BA /* BDBSplitViewController.m in Sources */,
E8660D66182852010024870C /* StickyDetailViewController.m in Sources */,
E8C61F4B1828507400DBA379 /* DrawerDetailViewController.m in Sources */,
E8D1B40C181B236100D4A6BA /* MasterViewController.m in Sources */,
E8D1B3CD181B179900D4A6BA /* main.m in Sources */,
E8D1B40B181B236100D4A6BA /* DetailViewController.m in Sources */,
E8D1B40B181B236100D4A6BA /* NormalDetailViewController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
4 changes: 2 additions & 2 deletions SplitViewDemo/AppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
#import "AppDelegate.h"
#import "BDBSplitViewController.h"
#import "MasterViewController.h"
#import "DetailViewController.h"
#import "NormalDetailViewController.h"


#pragma mark -
Expand All @@ -21,7 +21,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
self.window.backgroundColor = [UIColor whiteColor];

BDBSplitViewController *splitViewController = [[BDBSplitViewController alloc] initWithMasterViewController:[MasterViewController new]
detailViewController:[[DetailViewController alloc] initWithNibName:nil bundle:nil]];
detailViewController:[[NormalDetailViewController alloc] initWithNibName:nil bundle:nil]];

self.window.rootViewController = splitViewController;
[self.window makeKeyAndVisible];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// DetailViewController.h
// DrawerDetailViewController.h
// SplitViewDemo
//
// Created by Bradley Bergeron on 10/25/13.
Expand All @@ -12,7 +12,7 @@


#pragma mark -
@interface DetailViewController : BDBDetailViewController
@interface DrawerDetailViewController : BDBDetailViewController
<UISplitViewControllerDelegate>

@property (weak, nonatomic) IBOutlet UIView *labelContainerView;
Expand Down
67 changes: 67 additions & 0 deletions SplitViewDemo/View Controllers/DrawerDetailViewController.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
//
// DrawerDetailViewController.m
// SplitViewDemo
//
// Created by Bradley Bergeron on 10/25/13.
// Copyright (c) 2013 Bradley Bergeron. All rights reserved.
//

#import "DrawerDetailViewController.h"


#pragma mark -
@implementation DrawerDetailViewController

- (void)viewDidLoad
{
[super viewDidLoad];

self.title = @"Detail View";

self.splitViewController.masterViewDisplayStyle = BDBMasterViewDisplayStyleDrawer;
self.navigationItem.leftBarButtonItem = self.splitViewController.showHideMasterViewButtonItem;

if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7)
self.edgesForExtendedLayout = UIRectEdgeNone;

UIFont *socialIconFont = [UIFont fontWithName:@"SSSocialCircle" size:self.websiteLabel.font.pointSize * 2.0];

NSMutableAttributedString *websiteIcon = [[NSMutableAttributedString alloc] initWithString:@"rss"
attributes:@{NSForegroundColorAttributeName:self.websiteLabel.textColor,
NSFontAttributeName:socialIconFont,
NSLigatureAttributeName:@(2)}];
NSMutableAttributedString *twitterIcon = [[NSMutableAttributedString alloc] initWithString:@"twitter"
attributes:@{NSForegroundColorAttributeName:self.twitterLabel.textColor,
NSFontAttributeName:socialIconFont,
NSLigatureAttributeName:@(2)}];
NSMutableAttributedString *githubIcon = [[NSMutableAttributedString alloc] initWithString:@"octocat"
attributes:@{NSForegroundColorAttributeName:self.githubLabel.textColor,
NSFontAttributeName:socialIconFont,
NSLigatureAttributeName:@(2)}];

NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineHeightMultiple = 0.75;
paragraphStyle.alignment = NSTextAlignmentCenter;

NSDictionary *defaultAttributes = @{NSForegroundColorAttributeName:self.websiteLabel.textColor,
NSFontAttributeName:self.websiteLabel.font,
NSParagraphStyleAttributeName:paragraphStyle};

NSMutableAttributedString *websiteText = [[NSMutableAttributedString alloc] initWithString:[self.websiteLabel.text stringByReplacingOccurrencesOfString:@"website\n" withString:@"\n"] attributes:defaultAttributes];
NSMutableAttributedString *twitterText = [[NSMutableAttributedString alloc] initWithString:[self.twitterLabel.text stringByReplacingOccurrencesOfString:@"twitter\n" withString:@"\n"] attributes:defaultAttributes];
NSMutableAttributedString *githubText = [[NSMutableAttributedString alloc] initWithString:[self.githubLabel.text stringByReplacingOccurrencesOfString:@"github\n" withString:@"\n"] attributes:defaultAttributes];

[websiteText insertAttributedString:websiteIcon atIndex:0];
[twitterText insertAttributedString:twitterIcon atIndex:0];
[githubText insertAttributedString:githubIcon atIndex:0];

self.websiteLabel.attributedText = websiteText;
self.twitterLabel.attributedText = twitterText;
self.githubLabel.attributedText = githubText;

[self.websiteLabel sizeToFit];
[self.twitterLabel sizeToFit];
[self.githubLabel sizeToFit];
}

@end
Loading

0 comments on commit 4bb646d

Please sign in to comment.