0

I have configured a UISplitViewController on the iPad iteration of my app where in portrait mode, there's a UIBarButtonItem which calls out the Master View. In landscape, this view is displayed always (both Master and Detail View).

Because the iPad version is new for my users, and because they're used to seeing a Tab Bar on the iPhone, I want to make sure the users are alerted to where the menu has gone.

I want my Master View to be displayed the very first time the user launches the app.

So when the user presses the UIBarButtonItem, the Master view is displayed, but the very first time the app is launched, I want to have the Master View displayed (i.e. the UIButton BarButtonItem pressed).

I'm familiar with the process of checking when the app has been launched for the first time. I just need to know how to get the button to be called.

I have this code in the Detail:

#pragma mark - Split View Handler
-(void) turnSplitViewButtonOn: (UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *) popoverController {
    barButtonItem.title = NSLocalizedString(@"Master", @"Master");
    _splitViewBarButtonItem = barButtonItem;
    [self.navigationItem setLeftBarButtonItem:barButtonItem animated:YES];
    self.masterPopoverController = (EnvylopeMasterTableViewController *)popoverController;
}

-(void)turnSplitViewButtonOff
{
    NSLog(@"SplitViewButtonOff Called");
    // Called when the view is shown again in the split view, invalidating the button and popover controller.
    [self.navigationItem setLeftBarButtonItem:nil animated:YES];
    _splitViewBarButtonItem = nil;
    self.masterPopoverController = nil;

}

-(void) setSplitViewButton:(UIBarButtonItem *)splitViewButton forPopoverController:(UIPopoverController *)popoverController
{
    NSLog(@"Split View Being Called");
    if (splitViewButton != _splitViewBarButtonItem) {
        if (splitViewButton) {
            NSLog(@"Split View Button Being Called");
            [self turnSplitViewButtonOn:splitViewButton forPopoverController:popoverController];
        } else {
            [self turnSplitViewButtonOff];
            NSLog(@"Split View Button Not Being Called");
        }
    }
}

This is my code in the Master:

#pragma mark - Split View Delegate
- (void)splitViewController:(UISplitViewController *)splitController willHideViewController:(UIViewController *)viewController withBarButtonItem:(UIBarButtonItem *)barButtonItem forPopoverController:(UIPopoverController *)popoverController
{
    UINavigationController *navController = [[[self splitViewController ] viewControllers ] lastObject ];
    id vc = [[navController viewControllers] firstObject];

    self.popover = popoverController;

    [vc setSplitViewButton:barButtonItem forPopoverController:popoverController];
}

- (void)splitViewController:(UISplitViewController *)splitController willShowViewController:(UIViewController *)viewController invalidatingBarButtonItem:(UIBarButtonItem *)barButtonItem
{
    UINavigationController *navController = [[[self splitViewController ] viewControllers ] lastObject ];
    id vc = [[navController viewControllers] firstObject];
    self.popover = nil;
    [vc setSplitViewButton:nil forPopoverController:nil];
}

When the app is launched, the NSLog "Split View Being Called" and the "Split View Button Being Called" is being output to the console, but the button has not been pressed and the Master View is not being displayed.

I hope this makes sense and if anyone has any guidance on this, that would really be appreciated.

amitsbajaj
  • 1,304
  • 1
  • 24
  • 59

1 Answers1

1

I think that a decent approach would be to utilize NSUserDefaults to check and see if it's the users' first launch.

You can reference this post to learn how you can do this.

Once you have that value stored it'd be as simple as conditionally checking it upon app launch and doing your 'first app launch' setup if it is indeed their first launch.

edit:

You could programmatically touch the button once the app opens based around whether it's the users first time or not. Check out this.

Community
  • 1
  • 1
BlueBear
  • 7,469
  • 6
  • 32
  • 47
  • Hi Jonathan - thanks so much for the response. My apologies.. I'm actually familiar with that technique for checking if the user has launched before, using NSUserDefaults, but I'm a bit confused how to have the button pressed when it's first launched.. – amitsbajaj Oct 20 '14 at 14:18
  • @Lavanya I might not understand what you're trying to do entirely, but see if my edit helps you out at all. – BlueBear Oct 20 '14 at 14:28
  • Hi Jonathan - thanks for the updated answer and my apologies for the lack of clarity with that - but that second link helped me achieve what I wanted to here. Thanks very much! – amitsbajaj Oct 21 '14 at 06:13