Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3856182
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:53:26+00:00 2026-05-19T17:53:26+00:00

Say that I have a UIView which I would like to re-use in multiple

  • 0

Say that I have a UIView which I would like to re-use in multiple view controllers, given that it is a fairly generic UIView object with high re-usability value (like a UITextField or UISegmentedControl object). From my understanding it would be much easier to reuse this UIView if I wrote the UIView in code, rather than making a XIB using Interface Builder. I have reached this conclusion because if the UIView is written in code then I can simply initialize a new instance of that UIView in any view controller:

MyGreatReusableView *greatReusableView = [[MyGreatReusableView alloc] initWithFrame:CGRectMake(...)];

…and then directly access the properties and attributes of that UIView, just like with the stock UIView controls such as UITextField with it’s .text, .textColor, etc. properties.

However, if I create the UIView as a XIB then it must be tied (through either the File’s Owner or an IBOutlet on the View object in the XIB) to a specific view controller, and therefore can only be used in that view controller. Furthermore, I can only access the properties of controls on the XIB using the IBOutlets which are connected to that view controller.

I am thinking that I have completely misunderstood something with regards to XIB files, as this does seem to be quite a limitation! If someone could provide clarification on whether it is possible to re-use XIB files in multiple view controllers and, if so, provide an example of a code-based solution vs. a XIB-based solution I would be very much appreciative.

Thanks in advance for any assistance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T17:53:26+00:00Added an answer on May 19, 2026 at 5:53 pm

    It is indeed possible to use the same view in multiple view controllers. You were on the right track. The key is that you don’t have to use the view controller to which the view is tied. Here is what I do for re-usable table cells (that contain things like sliders)

    1. Create a new XIB file
    2. Create a new view (in my case this was a table cell)
    3. Set the UIViewController.view to be the view (again, table cell)
    4. I hook it up with this code (currently used in production):
      
      @implementation TableCellFactory
      +(UITableViewCell*) createCellInstanceFromXIBName:(NSString*)name {
              UIViewController* tmp = [[UIViewController alloc] initWithNibName:name bundle:nil];
              UITableViewCell* cell = (UITableViewCell*)[tmp view];
              DebugAssert([[cell class] isSubclassOfClass:[UITableViewCell class]], @"XIB view cell is not a subclass of UITableViewCell; xib name:%@",name);
              DebugAssert(cell != nil,@"cell is nil -- Xib name:%@",name);
              [cell retain];
              [tmp release];
              return cell;
      }
      @end
      
      
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say that I have 4 view controllers (call them FirstView,SecondView,ThirdView,FourthView) which are created
Say that i have a generic dictionary with data like this (I hope the
Say that you have a table with two (or more) columns which link to
Say that I have an article with multiple pages. Each page has a short
say that i have a project which lies in a folder called 'bin', and
I have a new gesture, (touch, drag onto other, release) which I would like
Say you have a UIView on top of which you have a bunch of
Let's say I have a ViewController that needs access to a view. In the
Say I have a subclass of UIView which I will call AnimatableView , where
So let's say I have a UIView that in its standard configuration spans the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.