错误线程1使用MRCountrypickerlibrary错误访问代码2(Error thread 1 exc bad access code 2 with MRCountrypickerlibrar

系统教程 行业动态 更新时间:2024-06-14 16:59:17
错误线程1使用MRCountrypickerlibrary错误访问代码2(Error thread 1 exc bad access code 2 with 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 。

类实现代码:

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.

更多推荐

本文发布于:2023-04-16 14:32:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/278553cb26169ff7e9b9fbedac00609c.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:错误   线程   代码   MRCountrypickerlibrary   Error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!