Tôi đang cố gắng để thêm một pickerview vào ứng dụng iphone của tôi, nhưng thay vì hiển thị chuỗi từ mảng của tôi nó cho thấy dấu hỏi. Có ai biết tại sao không? Tôi đã cố gắng tìm nó ra cho giờ vừa qua ... Đây là mã của tôi về bộ điều khiển có chứa các pickerview:bộ chọnXem hiển thị dưới dạng dấu chấm hỏi thay vì dữ liệu?
class NewIssueViewController: UIViewController, UIPickerViewDelegate {
var componentArr = ["component1","component2","component3","component4"]
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view.
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
@IBAction func CancelPressed(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
@IBAction func AddPressed(sender: AnyObject) {
self.dismissViewControllerAnimated(true, completion: nil)
}
func numberOfComponentsInPickerView(pickerView: UIPickerView!) -> Int {
return 1
}
func pickerView(pickerView: UIPickerView!, numberOfRowsInComponent component: Int) -> Int {
return componentArr.count
}
func pickerView(pickerView: UIPickerView!, titleForRow row: Int, forComponent component: Int) -> String! {
return componentArr[row]
}
}
Đối với bất cứ ai tự hỏi làm thế nào để thiết lập các đại biểu, xem hình ảnh này:. Http://static1.squarespace.com/static/52428a0ae4b0c4a5c2a2cede/t/543c1649e4b095b4c24a3d3c/1413224010678/dataSource-delegate. png? format = 750w – scottyseus
hoặc thêm 'self.YourIBOutletForPicker.delegate = self' –