3

I'm working on an iPad app that will need to hide/show the master controller of a split view.

Related SO answers note Matt Gemmell's MGSplitViewController:

MGSplitViewController would be perfect - even providing a way to adjust the ratio of master-to-detail views.

Fantastic! Except it doesn't play nice with the latest Xcode using storyboards and ARC.

I see a pull request (from 9 months ago) to convert to ARC for iOS4 but that still leaves it needing some work to be storyboard friendly.

Does anyone know of ongoing effort to update this jewel of open source to behave properly in the latest iOS development environment?

Failing that, examples/tutorials of how to integrate it into an Xcode storyboard/iOS5 project would be very useful.

Community
  • 1
  • 1
Thompsonian
  • 407
  • 5
  • 23

2 Answers2

2

It looks like if you wait long enough, every good package will get the attention it's due.

Thanks again to Matt Gemmell for a great package, and kudos to Heath Borders for taking the initiative.

Heath Borders port to iOS 5.1

Thompsonian
  • 407
  • 5
  • 23
  • I've been looking for exactly the same thing, and I might be missing something here, but I can't see how the latest commit from Heath is compatible with iOS5? For example it still contains all sorts of issues with ARC. – AustinRathe Aug 05 '12 at 15:08
  • 1
    @AustinRathe Is that with the "master2" branch? At the time I posted the question, I could find nobody even working on it. I've got a few more features to knock off my "must-have" list and then I'll begin integration of MGSplitViewController for a movable master/detail divider (that's why I haven't accepted an answer on this question yet). – Thompsonian Aug 06 '12 at 15:10
  • Yes, that's the one. I have had a play and got it working with ARC (will do the git thing at some point) but it still doesn't play nice with Storyboards. – AustinRathe Aug 06 '12 at 20:10
  • @AustinRathe So, you have all ARC related problems worked out, but it's just hooking it up from Xcode that remains as a problem? – Thompsonian Aug 09 '12 at 19:50
  • Yep. I have the example working in a new project with ARC, but it's all coming out of xib files. – AustinRathe Aug 10 '12 at 19:13
  • @AustinRathe I have not yet used storyboards to hook up MGSplitViewController - sorry to be of so little help on this topic which I brought attention to. – Thompsonian Oct 02 '12 at 17:26
  • @austin this is still on my to-do list, I think a good weekend would have it sorted, once I get the time :-) – AustinRathe Oct 03 '12 at 18:10
2

I was able to work around the storyboard issue. I had a universal app with master detail storyboard setup so I left them all in place and changed the initialization of the app to not use storyboards and instead programmatically set it up in my applicationDidFinishLaunching like so:

self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPad" bundle:nil];

    self.masterController = [storyboard instantiateViewControllerWithIdentifier:@"masterController"];
    self.detailController = [storyboard instantiateViewControllerWithIdentifier:@"detailController"];

    self.splitViewController = [[MGSplitViewController alloc] init];
    self.splitViewController.masterViewController = self.masterController;
    self.splitViewController.detailViewController = self.detailController;
    ACALandingVC* landingVC = [self.detailController.childViewControllers objectAtIndex:0];
    landingVC.splitController = self.splitViewController;
    self.splitViewController.delegate = landingVC;

    //self.splitViewController.splitWidth = 5;
    self.splitViewController.allowsDraggingDivider = YES;
    self.splitViewController.dividerStyle = MGSplitViewDividerStylePaneSplitter;
    self.splitViewController.splitPosition = 350;
    self.splitViewController.splitWidth = 10;


    self.window.rootViewController = self.splitViewController;
}
else {
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone" bundle:nil];
    UITabBarController* firstVC = [storyboard instantiateInitialViewController];
    self.window.rootViewController = firstVC;
    [[UINavigationBar appearance] setTintColor:[UIColor lightGrayColor]];
}

[self.window makeKeyAndVisible];

My AppDelegate.h looks like:

@class MGSplitViewController;

@interface ACAAppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;
@property (nonatomic, strong) MGSplitViewController* splitViewController;
@property (nonatomic, strong) UITabBarController* masterController;
@property (nonatomic, strong) UINavigationController* detailController;

@end
valheru
  • 2,552
  • 3
  • 20
  • 40