我添加了一个对我的警报进行个性化设置的 Pod (PCLBlurEffectAlert) 编辑警报、警报操作和警报文本字段后,出现此错误,并且无法使用文本字段。我能做什么?
let alert1 = PCLBlurEffectAlertController(title: NSLocalizedString("AGGENTRATA", comment: ""),
message: NSLocalizedString("insENTRATA", comment: ""),
effect: UIBlurEffect(style: .dark),
style: .alert)
alert1.addTextField( with: { (textField: UITextField!) in
textField.placeholder = NSLocalizedString("ENTRATA_LOCAL", comment: "") //impostiamo il segnaposto del field
textField.isSecureTextEntry = false //se fosse un campo Password mettremmo true
textField.keyboardType = UIKeyboardType.numberPad
} )
alert1.addAction(PCLBlurEffectAlertAction(title: NSLocalizedString("ANNULLA_LOCAL", comment: ""), style: .cancel, handler: { (action) in
UIView.animate(withDuration: 0.4, animations: {
self.blurVisual.effect = nil
})
}))
alert1.addAction(PCLBlurEffectAlertAction(title: NSLocalizedString("AGG", comment: ""), style: .default, handler: { (action) in
UIView.animate(withDuration: 0.4, animations: {
self.blurVisual.effect = nil
})
let textField = alert1.textFields![0] as UITextField
最佳答案
textfields
是 PCLBlurEffectAlertController
中的私有(private)变量。所以我们无法访问私有(private)变量。
fileprivate var textFields: [UITextField] = []
你可以这样使用:
var textfield1: UITextField?
let alert1 = PCLBlurEffectAlertController(title: NSLocalizedString("AGGENTRATA", comment: ""),
message: NSLocalizedString("insENTRATA", comment: ""),
effect: UIBlurEffect(style: .dark),
style: .alert)
alert1.addTextField( with: { (textField: UITextField!) in
textField.placeholder = NSLocalizedString("ENTRATA_LOCAL", comment: "") //impostiamo il segnaposto del field
textField.isSecureTextEntry = false //se fosse un campo Password mettremmo true
textField.keyboardType = UIKeyboardType.numberPad
self.textfield1 = textField
} )
alert1.addAction(PCLBlurEffectAlertAction(title: NSLocalizedString("AGG", comment: ""), style: .default, handler: { (action) in
let textField = (self.textfield1?.text as! NSString).floatValue
}))
关于ios - Swift - 由于 'textFields' 保护级别,无法访问 'fileprivate',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46478224/