Very frequently we reuse same view controllers when developing universal apps both for iPhone and iPad. But frequently some customization is needed, like:
IF iPad THEN
...
ELSE
...
So, in order to achieve such customization the controller might have some property that is set during initialization of the controller, or there might be custom constructors. Just curious is there design pattern that suites for such situations.
Don’t…. 🙂 Use a common class called for instance
MyClassand then sub-class itMyClass-iPad&MyClass-iPhoneand use two different XIB for each. Avoid using this kind of stuff (there is no need for it).Explanation:
The iPad version should only be aware of classes of the type
Something-iPadthis makes the code clean and creates a well defined architecture. If I jump into your code and someone tell’s me: “Ok Jacky Boy, you have to make changes on the iPad version”. I won’t care to look ath theSomething-iPhoneclasses. Most of the logic (business) should be on super classSomethingwhere the small tweaks should be on the sub-classes.On side note, on most of my projects, normally I don’t have anything on the
Something-iPhoneclasses, because the design is done on the XIB. On theSomething-iPadI would normally keep a reference to aUIPopOverController(just an example) and some rotations tweaks.Edit 1:
I would receive an
NSDictionaryon the init of theUIViewController, like this:After receiving this configurationDictionary, I would then use it on the
viewDidLoad(for example). You could then do some cool stuff like this: