1.设置单元格不可以被选中
override func setSelected(_ selected: Bool, animated: Bool) {
super.setSelected(selected, animated: animated)
if selected {
self.setSelected(false, animated: true)
}
}
2.更新UI(加载内容)
@IBOutlet weak var startDate: UILabel!
var project : Project? {
didSet{
updateUI()
}
}
var startDateValue : String?{
set{
if let dateValue = newValue{
if dateValue == "null"{
startDate?.text = "****-**-**"
}else{
let index = dateValue.index(dateValue.startIndex, offsetBy : 10)
startDate?.text = dateValue.substring(to: index)
}
} else{
startDate?.text = "****-**-**"
}
}
get{
return startDate?.text
}
}
func updateUI(){
if let p = project{
startDateValue = p.start_time
}
}
3.TextField
UITextFieldDelegate
var editable = false
func textFieldDidBeginEditing(_ textField: UITextField) {
if self.editable {
self.userInfoTextField.becomeFirstResponder()
} else {
self.userInfoTextField.resignFirstResponder()
}
}
4.处理点击方法
var changeState: (() -> Void)?
@IBAction func buttonClicked(_ sender: UIButton) {
self.changeState?()
}