Can't access UIImageView if created programmatically

前端 未结 2 1851
梦毁少年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.

提交回复
热议问题