1
我GOOGLE如何找到国家名单,并试图落实到PickerView
,但我被困在这一点上,我尝试做countries.count
它给了我一个错误说:名单的国家成为uipickerview SWIFT 3
无法将类型'int'的返回表达式转换为返回类型'string' 有什么建议吗?
import UIKit
class ViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate{
@IBOutlet weak var pickerValue: UIPickerView!
let countries = NSLocale.isoCountryCodes.map { (code:String) -> String in
let id = NSLocale.localeIdentifier(fromComponents: [NSLocale.Key.countryCode.rawValue: code])
return NSLocale(localeIdentifier: "en_US").displayName(forKey: NSLocale.Key.identifier, value: id) ?? "Country not found for code: \(code)"
}
func numberOfComponents(in pickerView: UIPickerView) -> Int {
return 1
}
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? {
return countries.count
}
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}