When converting my iPhone app to universal I needed to create a unique navigation bar for the detail view on the iPad. The old one featured a button, now I need to replicate the same behavior for the iPad Button, is it possible to do this without copying everything - If possible I´d like to avoid having one property for each and each have their own event handling methods.
2 Answers
Use the same view controller class files (.m and .h files) for the same view controller for both the iPad and iPhone (separate .xib files, one for iPhone and one for iPad). Be sure that you assign the same Custom Class for the view controller on the Identity Inspector tab in Interface Builder for the new iPad view controller.
Using the Assistant Editor in Interface Builder, simply CTRL-drag the button from the new iPad view controller to the existing IBOutlet property in the .h file or existing IBAction method in the .m file.

- 53,009
- 9
- 91
- 143
-
But they can only be lined to one unique object if I have an "@property () UIButton *button" trying to ctrl-drag when it´s already connected to another button in IB does not work – Tom Lilletveit Jul 24 '13 at 15:15
-
@TomLilletveit, is your `@property` an `IBOutlet`? Be sure that you assign the correct Custom Class for the view controller on the Identity Inspector tab in Interface Builder for the iPad. – Marcus Adams Jul 24 '13 at 16:20
-
I think the key here is you need to have 2 different xibs or Storyboards, one iPad size and one iPhone size. – Lance Jul 24 '13 at 16:24
-
@Lance, that's true. Maybe I was wrong, but I thought that was already done. I updated my answer. Thanks. – Marcus Adams Jul 24 '13 at 16:27
The common approach is to use one .xib file for iPhone and a separate .xib file for iPad. You can still use the same code for your view controller. It's also possible to programmatically drive your UI (with no .xib or storyboard).

- 2,589
- 1
- 13
- 10