UITableViewCell
which is defended programmatically. I use following code:
- (UIView *)viewFromNib
{
Class class = [self class];
NSString *nibName = NSStringFromClass(class);
NSArray *nibViews = [[NSBundle mainBundle] loadNibNamed:nibName owner:self options:nil];
UIView *view = [nibViews objectAtIndex:0];
return view;
}
- (void)addSubviewFromNib
{
UIView *view = [self viewFromNib];
self.bounds = view.bounds;
self.frame = view.frame;
self.viewNib = view;
[self addSubview:view];
[self.Button setTitle:@"hello"
forState:UIControlStateNormal]; // problem: button label is not changed
}
- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
...
[self addSubviewFromNib]; // adds subview from my Nib
...
}
change the class of the file owner of the nib file in interface builder to the correct class. reference the outlets like your normally do in interface builder.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.