LoginSignup
0
0

More than 1 year has passed since last update.

[Swift][Xcode]OutletCollectionsの場合のdelegate設定方法

Last updated at Posted at 2022-07-28

Error

複数パーツをOutletCollectionsで定義する時がありますが、その場合にいつも通りdelegate設定しようとするとエラーが出ます

    @IBOutlet var inputTextFields: [UITextField]!

    override func viewDidLoad() {
        inputTextFields.delegate = self
        super.viewDidLoad()    
    }

エラー

Value of type '[UITextField]' has no member 'delegate'


解決策

繰り返し処理のforEachで記述してあげる

    @IBOutlet var inputDataTextFields: [UITextField]!

    override func viewDidLoad() {
        inputTextFields.forEach({ $0.delegate = self })
        super.viewDidLoad()    
    }


参考:https://stackoverflow.com/questions/58428176/should-i-use-outletcollections-for-setting-delegate-property-of-multiple-textfie

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0