2017-02-28 32 views
0
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 
+0

你安慰了你的代表countryPhoneCodePicker函數嗎? – theduman

+0

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 } –

+0

沒有編譯錯誤..但是當應用程序崩潰時它崩潰並生成這個錯誤 –

回答

1

當你初始化你的選擇器中故事板,您將在身份檢查員處看到自定義課程部分。您必須將類和模塊都設置爲MRCountryPicker。否則,你會得到錯誤。

+0

我這樣做,並在兩個選項中選擇MRCountryPicker ..但仍然存在錯誤... –

+0

你在控制檯上是否有任何錯誤? – theduman

+0

有一點更多..我沒有使用cocoapods ora任何依賴關係經理..只是從庫複製和粘貼到我的項目 –