UIBittu
UIBittu

Reputation: 215

Reuse View for different Controllers Best way

I have 3 custom View Controllers having almost similar design.
How can I create a view (in Storyboard or using XIB) so that I can use the same view for my 3 View Controllers?

Upvotes: 11

Views: 3032

Answers (3)

Santina
Santina

Reputation: 52

I've had the same problem and created a Github repo to solve it: https://github.com/MaherKSantina/MSAutoView

Steps:

  • Download repo
  • Create a xib (ex: ListingView)
  • Create a class (should be the same name as xib)
  • Make the class inherit from MSAutoView
  • Set the class name in the Identity inspector of the xib to the class's name (Make sure you select the File's Owner in xib before changing the class)
  • Add a UIView to the storyboard
  • Assign its class to the one you created
  • The view should render the content of the xib

Detailed steps are available in the Readme of the repo.

Cheers

Upvotes: 0

Jignesh Mayani
Jignesh Mayani

Reputation: 7193

Make custom view with xib add common design that all 3 view controller. Now add UIView in that view controller and give super class of that UIView to that custom class and this way you can use this custom view on 3 controller

See this i have use same view in multiple controller

enter image description here

Upvotes: 3

Ajjjjjjjj
Ajjjjjjjj

Reputation: 675

/*******************/ Method 1: create a class Base of type UIViewController, implement all design here.

Next Create class A of type Class Base. Next Again, Create class B of type Class Base. Next Again, Create class C of type Class Base. this is called sub Classing.

Method 2:

use All different ViewController. if you have any UIView Similar for all viewControllers, create its different Class and Allocate its object from each class. then use delegates And block to perform operations between UIViewControllers and UIView class.

Upvotes: 0

Related Questions