IBOutlet instances are (null) after loading from NIB

前端 未结 5 1877
太阳男子
太阳男子 2021-02-18 22:30

I am working on an iPhone app and am getting (null) references to IBOutlet fields in my controller. I have a UIViewController subclass that is set as the File\'s Owner in my XIB

5条回答
  •  太阳男子
    2021-02-18 22:55

    This is how I do it:

    //in your view controller
    -(void)setUp
    {
        [self.cardView layoutIfNeeded];
        LearnCardPlainText *cardNib = [[[UINib nibWithNibName:@"LearnCardPlainText" bundle:nil] instantiateWithOwner:self options:nil] objectAtIndex:0];
        cardNib.frame = self.cardView.frame;
        [cardNib setUpWithPart:learnModel];
        [self.view addSubview:cardNib];
    }
    

提交回复
热议问题