我在我的项目中实现了assistolab下拉列表。但在某些viewcontroller中,它无法正常工作。显示,
无法在属性初始值设定项中使用实例成员 我的代码片段在下面给出
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()
}
这一错误令我感到困扰
let dropDown = DropDown()
请帮我解决此问题
答案 0 :(得分:0)
将您的代码更改为以下内容,以便在viewDidLoad
中初始化DropDown并将您的视图名称从“DropDown”更改为其他内容: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()
}
答案 1 :(得分:0)
您正在使用DropDown类作为属性名称。检查代码中的以下行 -
@IBOutlet weak var DropDown:UIView!
应该是这样的 -
@IBOutlet weak var dropDownView:UIView!