2017-07-31 59 views

回答

1

試試這個:

let alertView = UIAlertController(
     title: "Select item from list", 
     message: "\n\n\n\n\n\n\n\n\n", 
     preferredStyle: .alert) 

    let pickerView = UIPickerView(frame: 
     CGRect(x: 0, y: 50, width: 260, height: 162)) 
    pickerView.dataSource = self 
    pickerView.delegate = self 

    // comment this line to use white color 
    pickerView.backgroundColor = UIColor.lightGray.withAlphaComponent(0.2) 

    alertView.view.addSubview(pickerView) 

    let action = UIAlertAction(title: "OK", style: UIAlertActionStyle.default, handler: nil) 

    alertView.addAction(action) 
    present(alertView, animated: true, completion: { _ in 
     pickerView.frame.size.width = alertView.view.frame.size.width 
    }) 
+0

當執行功能我得到這個錯誤:「無法將類型'TwitterCampaigns.ViewController'(0x1088ac638)的值轉換爲'UIPickerViewDataSource'」。任何想法 ? –

+0

您是否已將數據源方法添加到您的viewController? – Bali

+0

我已經完成了它,UIPickerView正在顯示,但數據不在警告框中。 –