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 6868947
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:29:49+00:00 2026-05-27T03:29:49+00:00

I have a grid on screen. It is an instance of a UIView subclass.

  • 0

I have a grid on screen. It is an instance of a UIView subclass. In cells in the grid I want to add instances of subviews – another custom subclass of UIView – as the user interacts with the app. The subview itself is something I want to design in an XIB. Its controls represent state for that particular cell. It consists of a couple of UIControls (say a label and a button).

I already know I can load NIBs dynamically using

[[NSBundle mainBundle] loadNibNamed:@"MyNIB" owner:self options:nil];

and I know they’ll work if I set the File’s Owner property in the NIB to the view controller that’s responsible for the view these subviews will be added to. I use this to add some external NIBs to a UIScrollview in the main app screen.

What I want to know is how can I do this dynamically? I want to say something like:

MySubviewCell * sv = [[NSBundle mainBundle] loadNibNamed:@"MyNIB" owner:self options:nil];
[sv setFoo:@"Foo"];
[sv setBar:123];
[sv setFrame:myrect];
[mainView addSubview:sv];

But of course loadNibNamed doesn’t return me the subview instance, instead it returns an array of all the controls in the view.

EDIT File’s Owner in the MySubviewCell NIB will be a problem: there isn’t one, and there can’t be: I don’t know how many I’ll need. Should I be using something like an ArrayController?

EDIT 2 Please ignore the previous edit; I’ve left it in as the answer refers to it but it’s not the problem I thought it was.

Can I do this?

Thanks

  • 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-27T03:29:49+00:00Added an answer on May 27, 2026 at 3:29 am

    This is commonly used when designing table view cells in a nib. You’ve got two options:

    1. The object at index 0 of the returned array will be the “root” object in your nib.
    2. Create an outlet in your view controller of type MySubviewCell. Set your file’s owner class in the nib to your view controller, and link the outlet to the element in the nib you are interested in. When you load the nib with owner self, the outlet becomes populated. You can then configure it, add it to your array, and set the outlet back to nil to prepare to load the nib again for the next instance.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a grid, which I want to add a button at the top
I have a datagrid that occupies 100% of browser screen. I want the grid
I have a grid that has multiple rows. I want to hide/show one of
I have a grid view which is populated using a custom ImageAdapter class extending
We have a screen that shows a grid inside a tab control. There's one
I have created a custom control that simply draws a grid of squares on
I have two canvas's in a Grid, full scene images that I want to
Let's say I have a grid with multiselect option on, when user selects 4
I have a big grid of images. When a user mouseovers an image I
I am using vb.net code. I have grid view, please see the code below:

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.