I have a .xib file for my viewController. It contains a TableView and a UIView. The UIView is backed by a custom class – CommentsBarView (trying to position a small bar with a comments field underneath my tableView).
So in my Document Outline list I have:
- view
- tableView
- comments bar view
- UITextView
- UILabel
Custom class for “comments bar view” is CommentsBarView.
I have outlets connected from within CommentsBarView to the textfield and label.
(and from the ViewController to the tableView).
When I load my with controller with:
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
I can access the tableView property and change the appearance of the tableVIew, however, from my commentsBarView initWithCoder I can not set the text value on my textView and label:
- (id) initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:aDecoder];
if (self) {
[self.commentTextView setText:@"Helo, World!"];
[self.characterCountLabel setText:@"200"];
}
return self;
}
It seems as if these properties are not available at initWithCoder time.
If I manually, from my controllers initWithNibName, accesses self.commentsBar.label.text = 200, there is no problem.
Am I experiencing a timing issue where the views are not ready yet or can I not nest a view inside a viewControllers view and have it backed by a custom UIView subclass?
IB is confusing me a bit.
Thanks for any help given.
When loading from a XIB file, the IBOutlets are not ready in the
initmethods of the objects being unarchived.You need to override
awakeFromNibin your CommentsBarView to have access to the ready and connected IBOutlets.