0
  1. I have a UITableViewCell which is defended programmatically.
  2. I am trying to attach to it a simple Nib file.
  3. Nib has been created and fully configured. And I can add to Nib an images with IB and see that they appears when app is running. This means that Nib is loaded.
  4. But I still can not change any outlets (labels, buttons) on a Nib with code?
  5. What I should do solve the bit problem?

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
     ...
}
pmor
  • 5,392
  • 4
  • 17
  • 36

1 Answers1

0

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.

  • It seems strange but today I changed File's Owner to my custom class and make empty field Custom Class for my cell. And all works fine! Therefore, question is: If we have a cell with only one custom view should we set in IB the field Custom Class or we can just set File's Owner field? Or we should set both fields? (For anyone who have a same question: [link](http://stackoverflow.com/questions/15652139/whats-the-difference-between-custom-cell-class-vs-files-owner).) – pmor Apr 22 '14 at 06:06
  • File owner is where the xib is loaded. You set the class of the file owner so the ide knows which class to look for the IBOutlet declarations. You set the class of the custom view so the ide knows which instance of a class that custom view is. I'll let you figure out the answer based on what I just said. –  Apr 22 '14 at 17:52