Question

I am new to iOS,

I am trying to searching the best approach for creating reusable controls in iOS4+. For example if I created a View that could be used in multiple other views what is the best approach ?

I have created the View Called: HomeViewController.h HomeViewController.m HomeViewController.xib

in my HomeViewController file i have created 5 buttons and 5 labels programatically, there is nothing in .xib file

Now what i want to do is, i want to reuse all the components which i have created in HomeViewController and i want to use this control in my nextViewController

I do not want to write code again in my new View i will use my old code in a new View, In short i do not want to create same variable again in my new View.

Is there any way to achieve this ?

Any help will be appriciated.

Was it helpful?

Solution

Two possibilities come to mind:

  • create a new object that has only the code that you want to re-use and have your two view controllers each use an instance of that object to perform the common functions, or

  • create an abstract superclass that both of your view controllers inherit from and put the common code in it.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top