質問

  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
     ...
}
役に立ちましたか?

解決

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.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top