错误线程1 EXC坏接入码2 MRCountrypickerlibrary
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
当你初始化你的选择器中故事板,您将在身份检查员处看到自定义课程部分。您必须将类和模块都设置为MRCountryPicker。否则,你会得到错误。
我这样做,并在两个选项中选择MRCountryPicker ..但仍然存在错误... –
你在控制台上是否有任何错误? – theduman
有一点更多..我没有使用cocoapods ora任何依赖关系经理..只是从库复制和粘贴到我的项目 –
你安慰了你的代表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 } –
没有编译错误..但是当应用程序崩溃时它崩溃并生成这个错误 –