I have a Table view that I need to use a custom cell with a label and text field. I've designed the cell in the storyboard. I've set the custom cell's class to ItemRowCell
and I've given it a reuse identifier of itemRowCell
. I've connected the label and text field to the appropriate outlets in ItemRowCell
.
This is the code for my ItemRowCell class
class ItemRowCell: UITableViewCell {
@IBOutlet weak var itemDescription: UILabel!
@IBOutlet weak var quantity: UITextField!
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
}
}
In my data source I have this code
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "itemRowCell", for: indexPath) as! ItemRowCell
let (description, quantity) = self.currentItems[indexPath.row]
cell.itemDescription.text = description
cell.quantity.text = String(quantity)
return cell
}
Unfortunately, both outlets in the cell are nil.
断开并重新连接插座可解决此问题。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.