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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:10:54+00:00 2026-05-15T20:10:54+00:00

I’m probably not doing this correctly. Having not done an iPad app before I’m

  • 0

I’m probably not doing this correctly. Having not done an iPad app before I’m doing what seems natural to me.

I have a UIView that is going to be made of up other UIViews. Specifically, I want to dynamically create and add subviews to each of these subviews. In other words:

UIView
   |
   | --> UIView
           |
           | --> Dynamic UIView 1
           | --> Dynamic UIView 2
           | --> ...

I managed to get ‘Dynamic UIView 1’ by adding to its initWithFrame this bit of code to load the xib:

NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"ItemView" 
                                                  owner:[[ItemViewController alloc] init]
                                                options:nil];
ItemView *infoView = [nibViews objectAtIndex:0];
[self addSubview:infoView];

It works! The problem I’m having is that ‘Dynamic UIView n’ is always rendered at the top left corner of the screen. If I try to change the position with setFrame I get a black box at representing the frame however the actual control content remains in the top left.

Any ideas? Is there a better way to do this?

—– Update —–

Here is a screenshot of the root view.
Overview of main UIView http://www.freeimagehosting.net/uploads/460090996d.png

The entire control is call CurrentItemsViewController. The green area is a UIView within that I have linked back in code via a link in the IB, in the code sample it is called “itemsUIView”. Here is how I am adding items within CurrentItemsViewController.m

- (id)init {
[super initWithNibName:nil
                bundle:nil];

UITabBarItem *tbi = [self tabBarItem];
[tbi setTitle:@"Current"];

/* Approach 1 */
NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"ItemView" 
                                                  owner:[[ItemViewController alloc] init]
                                                options:nil];
ItemView *subItemView1 = [nibViews objectAtIndex:0];

/* Approach 2 - this apprach does Approach 1 in the initWithFrame method */
//ItemView *subItemView1 = [[ItemView alloc] initWithFrame:CGRectMake(120, 120, 354, 229)];

/* Approach 3 */
//ItemViewController *ctr = [[ItemViewController alloc] init];
//UIView *subItemView1 = [ctr view];

[[self view] addSubview:subItemView1];
// [[self itemsUIView] addSubview:subItemView1]; <-- doesn't render subItemView1 at all
[subItemView1 release];

[subItemView1 setFrame:CGRectMake(120, 120, 354, 229)];
[subItemView1 setBounds:CGRectMake(120, 120, 354, 229)];

return self;
}

Inside of ItemView.m I have this, it only gets call by Approach 2 and 3.

- (id)initWithFrame:(CGRect)frame {
if ((self = [super initWithFrame:frame])) {

    NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"ItemView" 
                                                      owner:[[ItemViewController alloc] init]
                                                    options:nil];
    ItemView *infoView = [nibViews objectAtIndex:0];
    [self addSubview:infoView];

}
return self;
}

As shown, I tried creating the ItemView 3 different ways and each one renders the same result. When I add the view as a subview of the root view I get this. Notice that a square appears where it should render, however ViewItem actually renders at the top left corner. In the sample above, when I add subItemView1 it doesn’t render anything at all.

alt text http://www.freeimagehosting.net/uploads/c6635ce860.png

  • 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-15T20:10:55+00:00Added an answer on May 15, 2026 at 8:10 pm

    Try setting the frame before you add it as a subview.

    Your code:

    NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"ItemView" 
                                                  owner:[[ItemViewController alloc] init]
                                                options:nil];
    ItemView *infoView = [nibViews objectAtIndex:0];
    self addSubview:infoView];
    

    Should be:

    NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"ItemView" 
                                                  owner:[[ItemViewController alloc] init]
                                                options:nil];
    ItemView *infoView = [nibViews objectAtIndex:0];
    infoView.frame = CGRectMake( put your rect here );
    [self addSubview:infoView];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

No related questions found

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.