class ViewController: UIViewController,UITextFieldDelegate,MRCountryPickerDelegate {
override func viewDidLoad() {
super.viewDidLoad()
countryPicker.countryPickerDelegate = self
countryPicker.showPhoneNumbers = true
countryPicker.setCountry("SI")
}
錯誤發生在:countryPicker.countryPickerDelegate = self
錯誤線程1 EXC壞接入碼2 MRCountrypickerlibrary
我曾嘗試解決,但不能得到它...給了我這個錯誤:
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
的定義,這裏是我的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
你安慰了你的代表countryPhoneCodePicker函數嗎? – theduman
yes and like like ... func countryPhoneCodePicker(_ picker:MRCountryPicker,didSelectCountryWithName name:String,countryCode:String,phoneCode:String,flag:UIImage) { self.countryName.text = name self.countryCode.text = countryCode self.phoneCode.text = phoneCode self.countryFlag.image = flag } –
沒有編譯錯誤..但是當應用程序崩潰時它崩潰並生成這個錯誤 –