All my IBOutlet are nil in viewDidLoad

前端 未结 3 2002
一个人的身影
一个人的身影 2020-12-17 14:42

I\'ve created a UIViewController that we can call MyViewController1. When I call MyViewController1, all my IBOutlet are <

相关标签:
3条回答
  • 2020-12-17 15:05

    Check whether IBoulet is linked properly with xib or not. Also check the files owner of your xib.

    If your class name or xib name is changed Try to allocate you viewcontroller with proper xibName

    MyViewController1 *vc = [[MyViewController1 alloc] initWithNibName:@"NibName" bundle:nil];
    
    0 讨论(0)
  • 2020-12-17 15:07

    I had the same problem after after breaking my head i realised naming the xib same as the class name solved my problem.

    0 讨论(0)
  • 2020-12-17 15:08

    You should probably use :

    MyViewController1 *vc = [[MyViewController1 alloc] initWithNibName:@"MyViewController1" bundle:nil]
    

    calling init won't do the match with your xib file and won't alloc your differents IBOutlet

    EDIT :

    There are two possibles solutions :

    First is calling init with super nibName :

    MyViewController1 *vc = [[MyViewController1 alloc] initWithNibName:@"MySUperViewController1" bundle:nil]
    

    The second is calling the super initWithNibName: in child init method :

    -(id)init {
       if (self = [super initWithNibName:@"MySuperViewController1" bundle:nil]) {
            // Init
       }
       return self;
    }
    
    0 讨论(0)
提交回复
热议问题