Home > Enterprise >  How do I access @IBOutlet from another class? Swift
How do I access @IBOutlet from another class? Swift

Time:10-28

Faced this problem, I need to link to code, but don't know how to do it. Tried just initialising the property with my view class type and also through delegation, but nothing works. How to access selectedImageView? Can you tell me please?enter image description here

enter image description here

CodePudding user response:

I don't know what else is happening in HomeViewController, but I don't see any reference to selectedImageView in the code you posted. HomeViewController would either need to be passed a reference to an instance of GridsView or an instance's selectedImageView particularly. If you have a reference to a GridsView instance in HomeViewController, you could access selectedImageView by doing

gridsViewInstance.selectedImageView

If you want to provide more context, I might be able to help more specifically.

CodePudding user response:

@IBOutles is a simple variable and it can be accessed the same way as every else variable. In your code you try to access selectedImageView var from HomeViewController, but it is property of GridsView class. So u need to access this var through GridsView instance (like gridsView. selectedImageView.image). It's quite obvious.

  • Related