Search code examples
xcodeuisplitviewcontrollermodalviewcontrolleripad

Dismissing MWPhotoBrowser View controller Modally in Split View


Ran into a snag and hoping for some insight here.

Overview: Universal app. The iPhone portion works great. The iPad portion has a split view controller. The master is a table view (left side) where the user selects a row and displays its detail (right side). Pretty standard stuff.

I’m using Xcode version 4.4.1 and my project is using Core Data, Storyboards and ARC.

DetailViewController: On the detail is a button that brings up another table view (within the detail) of user notes by date with a custom view. Each note can have an image associated with it. If a note has an image then a button with its photo icon is shown.

Example screenshot up to this point:

Example screenshot 1

MWPhotoBrowser: When the button of the photo icon is pressed I call MWPhotoBrowser (a wonderful library to show images in a standard way) to display the image or images. Single tap shows the one selected image, a double tap shows all images on the current table with the one chosen being viewed first. The image is displayed full screen.

To show the photo browser I use this code:

// Create the browser view.
MWPhotoBrowser *browser = [[MWPhotoBrowser alloc] initWithDelegate:self];

// Set browser options.
browser.wantsFullScreenLayout = YES;
browser.displayActionButton = YES;
[browser setInitialPageIndex:self.buttonRow];

UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:browser];

[self presentModalViewController:navController animated:YES];

The navController allows me to include a navigation controller with a “Done” button which calls doneButtonPressed.

Issue: All of the above works well until I press the “Done” button. The full screen photo browser dismisses properly. Unfortunately, the table view on the right side from where the user pressed the photo icon button is now gone (black). I thought the NotesViewController (right side) would remain there after photo browser was dismissed modally. Does calling a model view controller in a split view cause the other view controllers to be deleted?

Example screenshot showing problem:

enter image description here

The stacks on the detail view controller (right side) should be DetailViewController > NotesViewController > then call MWPhotoBrowser modally. After the photo browser is dismissed my self.navigationController.viewControllers.count equals 1 and I was expecting it to be 2.

Here’s the code that dismisses the MWPhotoBrowser:

- (void)doneButtonPressed:(id)sender {

if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {

    [self dismissViewControllerAnimated:YES completion:nil];
}
.
.
.

Hope someone can help me wrap my head around this.

As always, any help is greatly appreciated. Thanks!


Solution

  • I resolved my issue within the NoteViewController (the area turning black after the MWPhotoBrowser was dismissed).

    Within viewWillAppear I was setting my tableview to nil (to prevent cell overwrap) and reloading my table data.

    self.tableView = nil;
    
    [self.tableView reloadData];
    

    This works fine for the iPhone and when not returning from the MWPhotoBrowser’s full screen display on the iPad. For some reason that I do not understand, the above code causes the issue. I added additional logic to check if I’m returning from the full screen display and now all is fine. I’ll look into it more when time permits.