【发布时间】:2016-11-25 04:42:07
【问题描述】:
我在 Google 上搜索了如何找到国家/地区列表并尝试将其实施到 PickerView,但我被困在我尝试执行 countries.count 的这一点上,它给了我一个错误提示:
无法将“int”类型的返回表达式转换为“字符串”类型 有什么建议吗?
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.
}
}
【问题讨论】:
标签: arrays swift3 uipickerview