views:

64

answers:

2

Hi, I defined a UIView "RowOfThree" inwhich there are 3 labels. i also defined a UIView "Table" inwhich there are numer of objects of type "Row". the following code is in a method within object "Table":

RowOfThree *rowOfThree = [[RowOfThree alloc] init]; [self addSubview:rowOfThree];

for some reason it doesn't add the view. i tried defining the labels in "RowOfThree" both in IB and programmatically and it still didn't work. Thank you.

+1  A: 

Typically, a UIView (and the subclasses) are initialized using initWithFrame:. Maybe you did that in your own implementation of init, I don't know, but it may very well be that your view has a frame of {0,0,0,0} and therefore 0 height and 0 width. Set the frame by hand and tell us whether this works.

CGRect newFrame = CGRectMake(0.f, 0.f, 200.f, 40.f);
RowOfThree *rowOfThree = [[RowOfThree alloc] initWithFrame:newFrame];
[self addSubview:rowOfThree];
[rowOfThree release];
Pascal
Was typing in exactly this. :)
Chintan Patel
So that makes two of us, maybe we're on the right track after all. Too bad I can't split the millions of reputation points this answer will generate, I'm sorry. ;)
Pascal
A: 

SanHalo's answer is most likely correct but in addition, if you're using Interface Builder, you should not be directly initializing views that are defined in the nib. If you do, you have to use initFromNib instead of just init.

TechZen