0
我搞砸了與swift和我被困在與自定義TableViewCell.xib創建UIPickerView連接。我想要的功能如下:當我按開關按鈕出現一個pickerView,讓我選擇一個月將出現,而不是「選擇月」標籤。我真的不知道我應該在哪裏創建網點。與自定義tableViewCell.xib Swift PickerView
class TableViewCell: UITableViewCell {
@IBOutlet weak var leftImage: UIImageView!
@IBOutlet weak var label: UILabel!
@IBOutlet weak var rightImage: UIImageView!
override func awakeFromNib() {
super.awakeFromNib()
// Initialization code
}
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
// Configure the view for the selected state
}
func commonInit(_ imageName1: String, _ imageName2: String, text: String){
leftImage.image = UIImage(named: imageName1)
rightImage.image = UIImage(named: imageName2)
label.text = text
}
}
class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource {
let textData = ["Select Month"]
let datePicker = UIDatePicker()
@IBOutlet weak var tableView: UITableView!
override func viewDidLoad() {
super.viewDidLoad()
self.title = "UiTableView"
tableView.delegate = self
tableView.dataSource = self
let nibName = UINib(nibName: "TableViewCell", bundle: nil)
tableView.register(nibName, forCellReuseIdentifier: "tableViewCell")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return textData.count
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "tableViewCell", for: indexPath) as! TableViewCell
cell.commonInit("facebook", "twitter", text: textData[indexPath.item])
return cell
}
func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
return 170
}
func createDatePicker(){
let toolBar = UIToolbar()
toolBar.sizeToFit()
let doneButton = UIBarButtonItem(barButtonSystemItem: .done, target: nil, action: nil)
toolBar.setItems([doneButton], animated: false)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
我覺得我還不夠清楚。我已經連接了2個圖像視圖和標籤,但現在我想以某種方式將pickerView連接到標籤和開關按鈕,所以當我按下開關按鈕時標籤會根據pickerview進行更改。 – andino