发生错误: countryPicker.countryPickerDelegate = self
我试图解决但无法得到它...并给了我这个错误:
螺纹-1- EXC-坏存取码-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的定义
这是我的pod文件:
# 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 class ViewController: UIViewController,UITextFieldDelegate,MRCountryPickerDelegate { override func viewDidLoad() { super.viewDidLoad() countryPicker.countryPickerDelegate = self countryPicker.showPhoneNumbers = true countryPicker.setCountry("SI") }Error occured on : countryPicker.countryPickerDelegate = self
I have tried to solve but can't get it... and gives me this error:
thread-1-exc-bad-access-code-2-
I am using MRCountrypickerlibrary.
class implementation code:
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!) }updated code is above and it is the definition of MRCountryPicker
and here is my pod file:
# 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检查员处看到自定义类部分。 您必须将类和模块都设置为MRCountryPicker。 否则你会收到错误。
When you init your picker in storyboard you will see custom class section at identitiy inspector. You have to set both class and module to MRCountryPicker. Otherwise you will get the error.
更多推荐
发布评论