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
答案 0 :(得分:1)
当您在故事板中初始化选择器时,您将在身份检查员处看到自定义课程部分。您必须将类和模块都设置为MRCountryPicker。否则你会收到错误。