I'm sure this question is asked before but I couldn't find a solution for it.
I have a UITableViewController
with static cells
, I have 4 sections
(so far) and each section
only has 1 cell
.
this is a part of the first Cell of First section
and this is the corresponding TableViewCell file,
AllgemeineProduktdatenCell.swift
class AllgemeineProduktdatenCell: UITableViewCell{
// MARK: - Outlets
@IBOutlet weak var AngebotsnameTextF: UITextField!
@IBOutlet weak var Referenznummer: UITextField!
@IBOutlet weak var modelTextF: UITextField!
@IBOutlet weak var bemerkungTextF: UITextView!
@IBOutlet weak var extrasTextF: UITextView!
@IBOutlet weak var ursprLadenPreisEuroTextF: UITextField!
@IBOutlet weak var ursprLadenPreisCentTextF: UITextField!
@IBOutlet weak var AngebotsPreisEuroTextF: UITextField!
@IBOutlet weak var AngebotsPreisCentTextF: UITextField!
// Bereich Möbel
@IBOutlet weak var bereichMoebelLabel: UILabel!
@IBOutlet weak var bereichMoebelPicker: UIPickerView!
@IBAction func showHideBereichMoebelPicker(_ sender: Any) {
if bereichMoebelPicker.isHidden{
bereichMoebelPicker.isHidden = false
} else{
bereichMoebelPicker.isHidden = true
}
}
// Hersteller
@IBOutlet weak var chosenHerstellerLabel: UILabel!
@IBOutlet weak var herstellerPickerView: UIPickerView!
@IBAction func showHideHerstellerPicker(_ sender: UIButton) {
if herstellerPickerView.isHidden{
herstellerPickerView.isHidden = false
} else{
herstellerPickerView.isHidden = true
}
}
// Anzeigen auch auf eigener Webseite
@IBOutlet weak var anzeigenAuchAufEigenerWebseiteSwitch: UISwitch!
@IBAction func anzeigenAufWebsiteSwitch(_ sender: Any) {
}
// Start des Angebot
@IBOutlet weak var startDesAngebotChosenDateLabel: UILabel!
@IBOutlet weak var startDesAngebotDatePicker: UIDatePicker!
@IBAction func hideShowStartDesAngebotDP(_ sender: Any) {
if startDesAngebotDatePicker.isHidden{
startDesAngebotDatePicker.isHidden = false
} else{
startDesAngebotDatePicker.isHidden = true
}
}
func setUpAllgemeineFields(product: ItemsClass){
AngebotsnameTextF.text = "ABED"//product.title
Referenznummer.text = product.artikel_nummer
modelTextF.text = product.typ_kategorie
}
}
Imagine that I have similar files for each of my cells.
and this is my main View file:
AddEditVC.swift
class AddEditVC: UITableViewController {
var product_obj: ItemsClass!
override func viewDidLoad() {
super.viewDidLoad()
}
// MARK: - Table view data source
override func numberOfSections(in tableView: UITableView) -> Int {
return 4
}
override func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 1
}
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if let cell = tableView.dequeueReusableCell(withIdentifier: "AllgemeineProduktdaten") as? AllgemeineProduktdatenCell{
cell.setUpAllgemeineFields(product: product_obj)
return cell
} else{
print("FFFFFFAAAAAILD")
return AllgemeineProduktdatenCell()
}
}
}
when I run this application the cell is blank and I even cannot see my View
s but when I comment out the cellForRowAt
function then I can see my outlets
but the fields are empty.
How can I fill the fields of my cell with my object? how should I specify that which cell to be filled (I need it also for my other cells of other sections)
UPDATE:
this is an overview of my TableViewController
Thank you in advance and sorry for such a long question
Once you set up all prototype cell classes and reuse identifiers, you can use below code to generate the cells. Since you didn't include the exact code for your classes, this is just a skeleton code, but you should be able to fill in the gaps.
I managed to do it by asking another question with the help of André, I used a Vertical
UIStackView
and added a button in first row (and whatever element in the as other rows), then add anIBAction
to the code for theUIButton
as follow:This will make the
StackView
to collapse, no need to go through complexity ofTableView
s