斯威夫特 - ' textFields'由于'fileprivate'而无法访问保护水平

时间:2017-09-28 20:59:40

标签: ios iphone swift cocoapods textfield

我添加了一个个性化我的警报的广告连播(PCLBlurEffectAlert) 编辑警报,警报和警报文本字段后,我有这个错误,我无法使用文本字段。我该怎么办?

enter image description here

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

1 个答案:

答案 0 :(得分:0)

textfieldsPCLBlurEffectAlertController中的私有变量。所以我们无法访问私有变量。

  

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
}))