Note that there are some explanatory texts on larger screens.

plurals
  1. POUIView not being positioned with setFrame
    primarykey
    data
    text
    <p>I'm probably not doing this correctly. Having not done an iPad app before I'm doing what seems natural to me.</p> <p>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:</p> <pre><code>UIView | | --&gt; UIView | | --&gt; Dynamic UIView 1 | --&gt; Dynamic UIView 2 | --&gt; ... </code></pre> <p>I managed to get 'Dynamic UIView 1' by adding to its initWithFrame this bit of code to load the xib:</p> <pre><code>NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:@"ItemView" owner:[[ItemViewController alloc] init] options:nil]; ItemView *infoView = [nibViews objectAtIndex:0]; [self addSubview:infoView]; </code></pre> <p>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.</p> <p>Any ideas? Is there a better way to do this?</p> <p>----- Update -----</p> <p>Here is a screenshot of the root view. <a href="http://www.freeimagehosting.net/uploads/460090996d.png" rel="nofollow noreferrer">Overview of main UIView http://www.freeimagehosting.net/uploads/460090996d.png</a></p> <p>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</p> <pre><code>- (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]; &lt;-- doesn't render subItemView1 at all [subItemView1 release]; [subItemView1 setFrame:CGRectMake(120, 120, 354, 229)]; [subItemView1 setBounds:CGRectMake(120, 120, 354, 229)]; return self; } </code></pre> <p>Inside of ItemView.m I have this, it only gets call by Approach 2 and 3.</p> <pre><code>- (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; } </code></pre> <p>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.</p> <p><a href="http://www.freeimagehosting.net/uploads/c6635ce860.png" rel="nofollow noreferrer">alt text http://www.freeimagehosting.net/uploads/c6635ce860.png</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload