错误线程1带有MRCONTRYPICKERLIBRARY的EXC不良访问代码2


class ViewController: UIViewController,UITextFieldDelegate,MRCountryPickerDelegate {

 override func viewDidLoad() {
        super.viewDidLoad()

     countryPicker.countryPickerDelegate = self
     countryPicker.showPhoneNumbers = true
     countryPicker.setCountry("SI")
 }

发生错误:countryPicker.countryPickerDelegate = self

我试图解决但无法理解...并给我这个错误:

thread-1-exc-bad-access-code-2-

我正在使用mrcountrypickerlibrary。

类实施代码:

open class MRCountryPicker: UIPickerView, UIPickerViewDelegate, UIPickerViewDataSource {
var countries: [Country]!
open weak var countryPickerDelegate: MRCountryPickerDelegate?
open var showPhoneNumbers: Bool = true
override init(frame: CGRect) {
    super.init(frame: frame)
    setup()
}
required public init?(coder aDecoder: NSCoder) {
    super.init(coder: aDecoder)
    setup()
}
func setup() {
    countries = countryNamesByCode()
    super.dataSource = self
    super.delegate = self
}
// MARK: - Country Methods
open func setCountry(_ code: String) {
    var row = 0
    for index in 0..<countries.count {
        if countries[index].code == code {
            row = index
            break
        }
    }
    self.selectRow(row, inComponent: 0, animated: true)
    ****let country = countries[row]****
    if let countryPickerDelegate = countryPickerDelegate {
        countryPickerDelegate.countryPhoneCodePicker(self, didSelectCountryWithName: country.name!, countryCode: country.code!, phoneCode: country.phoneCode!, flag: country.flag!)
    }

上面更新的代码,这是Mrcountrypicker的定义

这是我的吊舱文件:

# Uncomment the next line to define a global platform for your project
 platform :ios, '9.0'
target 'myapp' do
  # Comment the next line if you're not using Swift and don't want to use dynamic frameworks
  use_frameworks!
  # Pods for myapp
    pod 'MRCountryPicker'
end

当您在故事板中启动您的选择器时,您将在Identitiy Inspector中看到自定义类部分。您必须将课程和模块设置为Mrcountrypicker。否则您将获得错误。

最新更新