Storyboard and custom init

前端 未结 3 1132
醉话见心
醉话见心 2020-12-15 17:51

I recently tried working with the MainStoryboard.storyboard within Xcode and so far It\'s going pretty good and I\'m wondering why I\'ve never used it before. While playing

3条回答
  •  -上瘾入骨i
    2020-12-15 18:02

    You can instantiate viewcontroller in -init method.

     - (instancetype)init
     {
        UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:[NSBundle mainBundle]];
    
       self = [storyboard instantiateViewControllerWithIdentifier:@"MyViewController"];
    
       if(self)
       {
        //default initialization
    
       }
       return  self;
     }
    

    and the in your custom init method

     - (instancetype)initWithImages:(NSArray *)images
     {
       self = [self init];
    
       if(self)
       {
         self.images = images;
       }
    
       return  self;
     }
    

提交回复
热议问题