سؤال

I have an iPhone storyboard with a UITableView that segues to a detail view using a navigation controller. I'm trying to reuse my classes in the iPad version of the same app inside a master-detail UI.

Here's how my storyboards look to visualize what I'm doing:

iPhone and iPad storyboards

I want to reuse as much code as possible, and so far I've been successful in reusing my PPAircraftViewController class with its aircraftTableView.

Question: Since the iPad app already uses PPAircraftViewController to hold the table and detail views, how can I reuse my PPAircraftDetailViewController class with all its code and IBOutlets?


Xcode 5, targeting iOS 6 & 7, UISplitViewController not an option since all of this is embedded within a parent navigation controller.

هل كانت مفيدة؟

المحلول

I finally found what I was looking for. I can't believe it took me so long to remember it, but the perfect solution for this scenario is a UIContainerView.

It lets me embed the PPAircraftDetailViewController inside its containing view controller as pictured below.

Thanks, everyone!

UIContainerView

نصائح أخرى

On the iPhone your PPAircraftDetailViewController gets pushed on the navigation stack by the PPAircraftViewController.

That makes either the one or the other visible to the user.

On the iPad, Apple provides a mechanism to show a MasterView and a DetailView side by side in a UISplitViewController.

In that case, the MasterViewController does not "push" the DetailViewController, but activates it through IBOutlets and Delegation.

You can have your PPAircraftViewController as (part of) the MasterViewController and your PPAircraftDetailViewer as (part of) the DetailViewController.

It will require some tweaking, but will also save you a lot of effort as sizing and rotating will be done by the SplitViewController.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top