0

I have a Master-Detail iOS app, built from standard XCode template with storyboards. I need to display a view with a browser on most of the items, and a settings form (using FXForms) when user clicks the "Settings" item in UITableView of the Master.

I have found a way do it in iPhone, but can't find one in iPad. In iPhone storyboard I create another view controller and make another segue connection from Master to the new view controller. Then I do the following in didSelectRowAtIndexPath

if(indexPath.section == 0 && indexPath.row == 2) // settings
    [self performSegueWithIdentifier:@"showSettings" sender:self];
else
    [self performSegueWithIdentifier:@"showDetail" sender:self];

With this the Settings view come into place when I click Settings. Navigation back and forth also works.

However, in iPad the detailViewController seems to be always there, on the right of the SplitViewController. How can I modify the storyboard and/or code to swap default view to Settings and then swap back again?

I also found that default template from XCode creates "relationship" segues for iPad storyboard, a type which is not there in iPhone storyboard, and cannot be named like "showSettings" or "showDetail" as I did in iPhone case.

Timothy Ha
  • 399
  • 3
  • 7
  • Would it be an option for you to use the same storyboard for both? Do you not want the SplitView at all or is it just you're trying to replace the SplitView instead of part of the SplitView? – Shriike Nov 04 '14 at 20:27
  • XCode creates two different storyboards for iPhone and iPad in the standard Master-Detail example. I don't see a way for iPhone to share the same storyboard, because Master-Detail in iPhone is like switching from one full-screen view to another, and iPad uses a "sidebar"-like Master. And I would like to find a way to replace a part of the SplitView in case of iPad. – Timothy Ha Nov 04 '14 at 20:44
  • With XCode 6 you can use single Storyboard for both iPhone & iPad and if you target iOS8 you can even use UISplitViewController on both iPhone and iPad. – Sachin Palewar Nov 06 '14 at 08:16
  • @SachinPalewar - probably, it won't be Master-Detail any more if UISplitViewController is used for iPhone. I will test more with replacing detailViewController and provide solution here in the issue. Thanks. – Timothy Ha Nov 06 '14 at 09:44
  • @SachinPalewar - I've reviewed your tip about single Storyboard. Seems like Apple has changed Master-Detail template in XCode to do UISplitViewController for iPhone, too. Somebody is discussing that here: http://stackoverflow.com/questions/25875618/uisplitviewcontroller-in-portrait-on-iphone-shows-detail-vc-instead-of-master Thanks! – Timothy Ha Nov 08 '14 at 10:58
  • 1
    I also did a Multiple-Detail sample at http://swiftwala.com/multiple-detail-views/ You may check it out. – Sachin Palewar Nov 08 '14 at 11:03
  • @SachinPalewar your solution looks similar to what I did for iPhone case. And that worked for iPad, too? – Timothy Ha Nov 08 '14 at 11:11
  • @SachinPalewar - so the iPad solution is to create another pair of (NavigationController, ViewController) and use "replace" seque (now it's renamed to a better "Show Detail" type). – Timothy Ha Nov 08 '14 at 11:25
  • Yep works fine on all devices. Can download the code from GitHub and see for yourself. Link in the post. – Sachin Palewar Nov 08 '14 at 11:25
  • @SachinPalewar - Yes, I did just that, I downloaded your code and took a look at the storyboard :-) Thanks again. – Timothy Ha Nov 08 '14 at 11:30

1 Answers1

0

From the comments to the original post I found that:

  1. If I target iOS 8, I can use same storyboard for both iPhone and iPad, and then I can use "replace" segues (now called "show detail" segues) to switch to another detail view. Very convenient, but that is not available for iOS 7 yet.

  2. As for iOS 7 I can use segues to support iPhone, and for iPad I have to do something like this (FXForms if the neat library I am using to show a view with options).

So my code for iPad (in - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath for a specific row). I do backup the current lastObject of self.splitViewController.viewControllers to restore for other rows of the table view in Master.

FXFormViewController *controller = [[FXFormViewController alloc] init];
IBSettingsForm *settingsForm = [[IBSettingsForm alloc] init];
settingsForm.fontSize = 12;
controller.formController.form = settingsForm;

// this is created so that my new view would have a navigation bar    
UINavigationController *navigationController  = [[UINavigationController alloc] init];
[navigationController pushViewController:controller animated:false];

self.splitViewController.viewControllers = [NSArray arrayWithObjects:[self.splitViewController.viewControllers objectAtIndex:0],
    navigationController, nil];
Timothy Ha
  • 399
  • 3
  • 7