Can't access UIImageView if created programmatically

前端 未结 2 1822
梦毁少年i
梦毁少年i 2021-01-28 05:50

If I create a UIImageView via Storyboard and add it as a @property into a ViewController.h, I can access that UIImageView fro

相关标签:
2条回答
  • 2021-01-28 06:14

    The answer AgnosticDev is trying to say here is to add an ivar to your view controller's .h file... e.g.:

    @implementation YHLViewController : ViewController
    {
        UIImageView * currImageView;
    }
    

    And then in your "viewDidLoad" method, you can allocate and initialize it via:

    currImageView = [[UIImageView alloc] init];
    

    and have access to it from anywhere else in your view controller.

    0 讨论(0)
  • 2021-01-28 06:19

    You would need to create your UIImageView in your header file and then it would be available throughout the rest of the view. You will need to add it to the view in viewDidLoad though.

             Header
             UIImageView *image;
    
             Main // ViewDidLoad
             image = [UIImageView alloc] .....
             [self.view addSubView image];
    
    
             Main Function .....
             [image setImage ....
    
    0 讨论(0)
提交回复
热议问题