iosiphoneipadoptimizationbest-fit

Best code practice iPhone & iPad custom view controllers


This question may looks like silly. But I want to know & check the correct way to write & group my code.

Consider I'm writing an app for both iPhone & iPad. I'm writing by code and not using storyboard.

What is the suggested way to keep the code?

I hereby explained what did I make the code more visible and more reusable. Please correct me in case of any mistake.

Say, my controllers are iPhoneListViewController and iPadListViewController

This both controllers are totally customized controllers and they are the child of ListViewController which contains some common methods (both UI related and function related). ListViewController is the child class of UIViewController.

Other custom controllers, custom views, singleton classes, protocols was separately saved.

Questions:

  1. Am I using optimal way to code?
  2. Should I separate HD/non HD code?

Solution

  • 1). As you are targeting both iPhone & iPad, you can have two separate classes for these. According to my opinion, there is no better way of segregating the code other than this.

    Just a piece of advice for the UI part though: You can use file names as MyListViewController~iPhone.xib & MyListViewController~iPad.xib for your files. The advantage of this approach is, iOS will automatically pick the correct xib according to the type of device your app is running on. i.e. You can make an instance like: MyListViewController lvc= [[MyListViewController alloc]initWithNibName:"MyListViewController" bundle:nil];.

    2). Separating HD/Non HD code doesn't look good at all. By looking into the number of different device sizes, I think you should use autolayouts to make your UI responsive irrespective of device size.