How to make IBOutlets out of an array of objects?

后端 未结 5 1390
南旧
南旧 2020-12-30 20:13

I want to make an array with a bunch of UIImageViews I have in Interface Builder. Instead of having 20 or 30

IBOutlet UIImageView *img1;

a

5条回答
  •  爱一瞬间的悲伤
    2020-12-30 20:59

    Here is more easier way to do it.

    Follow these steps to create an array of outlets an connect it with IB Elements:

    • Create an array of IBOutlets
    • Add multiple UIElements (Views) in your Storyboard ViewController interface
    • Select ViewController (In storyboard) and open connection inspector
    • There is option 'Outlet Collections' in connection inspector (You will see an array of outlets there)
    • Connect if with your interface elements

    -

    class ViewController2: UIViewController {
    
    
        @IBOutlet var collection:[UIView]!
    
    
        override func viewDidLoad() {
            super.viewDidLoad()
        }
    }
    

    enter image description here

提交回复
热议问题