ios - Swift - 由于 'textFields' 保护级别,无法访问 'fileprivate'

标签 ios iphone swift cocoapods textfield

我添加了一个对我的警报进行个性化设置的 Pod (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

最佳答案

textfieldsPCLBlurEffectAlertController 中的私有(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/

相关文章:

ios - 将 WKInterfaceController 滚动回顶部

ios - Xcode 7 - 导出期间发生错误 - IPA 没有主包

iphone - 如何编写VIN扫描工具

iOS 共享扩展隐藏在所选项目的数量上

ios - 如何快速实现自动完成表格 View 谷歌地图?

ios - 使用 Sprite Kit 画线时播放声音

ios - URL 未在 UIWebview 中加载,# 转换为 %23

iphone - 当 UITextField 成为第一响应者时,如何使 UIScrollView 自动滚动

iphone - (iPhone SDK) 如何通过标签id修改UIButton?

swift - 使用 Swift 的自定义事件指示器