Reputation: 1970
I created Custom UIView with bunch of labels. label1, label2,
UIView *testContentView = [[[UINib nibWithNibName:@"testContentView" bundle:nil] instantiateWithOwner:nil options:nil] objectAtIndex:0];
How do I access the label and setting text ?
Upvotes: 0
Views: 255
Reputation: 3104
In order to access your custom properties, you need to cast the UIView to a TestContentView.
TestContentView *testContentView = (TestContentView *)[[[UINib nibWithNibName:@"testContentView" bundle:nil] instantiateWithOwner:nil options:nil] objectAtIndex:0];
Upvotes: 0
Reputation: 21013
You need to define them on your interface.
@interface TestContentView : UIView
@property (weak, nonatomic) IBOutlet UILabel *label1;
@property (weak, nonatomic) IBOutlet UILabel *label2;
@end
And then...
testContentView.label1.text = @"foo";
testContentView.label2.text = @"bar";
Edit
Added IBOutlet
to the properties since you are using a NIB, you will also need to wire these up in Interface Builder.
Upvotes: 2