1

i have implemented assistolab dropdown in my project.but in some viewcontroller it could not work properly.it shows,

cannot use instance member within property initializer my code snippet is given below

class MobileTopUpVC: UIViewController,UITextFieldDelegate {

    let dropDown = DropDown() //error is here

    @IBOutlet weak var mobileTopUpImag: UIImageView!
    @IBOutlet weak var amountTxt: UITextField!
    @IBOutlet weak var mobileNumberTxt: UITextField!
    @IBOutlet weak var operatorTxt: UITextField!
    @IBOutlet weak var countryTxt: UITextField!
    @IBOutlet weak var DropDown: UIView!

    @IBOutlet weak var backGroundView: UIView!
    var textArray = [UITextField]()
    var countryArray:[String] = colors.countryArray
    var operatorArray:[String] = colors.opArray





    @IBOutlet weak var proceedButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()




        backGroundView.layer.cornerRadius = backGroundView.frame.width/2
        backGroundView.clipsToBounds = true
        //countryArray = colors.countryArray
          backGroundView.layer.borderWidth = 3
        backGroundView.layer.borderColor = colors.second.cgColor
        textArray = [countryTxt,operatorTxt,amountTxt,mobileNumberTxt]
        let view1:UIView! = UIView()

        view1.frame = CGRect(x: 0, y: 0, width: 0, height: 0)

        countryTxt.inputView  = view1
        operatorTxt.inputView  = view1
//        countryTxt.layer.borderWidth = 1
//        countryTxt.layer.borderColor = UIColor.green.cgColor
//        countryTxt.borderStyle = UITextBorderStyle.bezel
        borderStyle()
        proceedButton.Cradius(size: 15.0)
        mobileTopUpImag.image = mobileTopUpImag.image?.withRenderingMode(.alwaysTemplate)
        mobileTopUpImag.tintColor = colors.second
        countryDropDown()
    }

the error is troubling me in this line

let dropDown = DropDown()

please help me to resolve this

sarath m
  • 11
  • 1

2 Answers2

0

Change your code to the following so your DropDown is initialised in the viewDidLoad

and also change your View name From "DropDown" to something else :D

class MobileTopUpVC: UIViewController,UITextFieldDelegate {

    let dropDown: DropDown? //Changed**

    @IBOutlet weak var mobileTopUpImag: UIImageView!
    @IBOutlet weak var amountTxt: UITextField!
    @IBOutlet weak var mobileNumberTxt: UITextField!
    @IBOutlet weak var operatorTxt: UITextField!
    @IBOutlet weak var countryTxt: UITextField!
    @IBOutlet weak var dropDownView: UIView! // Change your VIEW NAME!!!

    @IBOutlet weak var backGroundView: UIView!
    var textArray = [UITextField]()
    var countryArray:[String] = colors.countryArray
    var operatorArray:[String] = colors.opArray





    @IBOutlet weak var proceedButton: UIButton!

    override func viewDidLoad() {
        super.viewDidLoad()
        dropDown = DropDown()




        backGroundView.layer.cornerRadius = backGroundView.frame.width/2
        backGroundView.clipsToBounds = true
        //countryArray = colors.countryArray
          backGroundView.layer.borderWidth = 3
        backGroundView.layer.borderColor = colors.second.cgColor
        textArray = [countryTxt,operatorTxt,amountTxt,mobileNumberTxt]
        let view1:UIView! = UIView()

        view1.frame = CGRect(x: 0, y: 0, width: 0, height: 0)

        countryTxt.inputView  = view1
        operatorTxt.inputView  = view1
//        countryTxt.layer.borderWidth = 1
//        countryTxt.layer.borderColor = UIColor.green.cgColor
//        countryTxt.borderStyle = UITextBorderStyle.bezel
        borderStyle()
        proceedButton.Cradius(size: 15.0)
        mobileTopUpImag.image = mobileTopUpImag.image?.withRenderingMode(.alwaysTemplate)
        mobileTopUpImag.tintColor = colors.second
        countryDropDown()
    }
Siyavash
  • 970
  • 9
  • 23
0

You are using DropDown class as property name. Check below line in your code-

@IBOutlet weak var DropDown: UIView!

It should be something like this-

@IBOutlet weak var dropDownView: UIView!

Vishwas Singh
  • 1,497
  • 1
  • 18
  • 16