uitableview - UITableViewController filling cells of different sections with Values -
i'm sure question asked before couldn't find solution it. have uitableviewcontroller
static cells
, have 4 sections
(so far) , each section
has 1 cell
.
this part of first cell of first section
and 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 have similar files each of cells.
and 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 run application cell blank , cannot see view
s when comment out cellforrowat
function can see outlets
fields empty.
how can fill fields of cell object? how should specify cell filled (i need other cells of other sections)
update: overview of tableviewcontroller
thank in advance , sorry such long question
once set prototype cell classes , reuse identifiers, can use below code generate cells. since didn't include exact code classes, skeleton code, should able fill in gaps.
override func tableview(_ tableview: uitableview, cellforrowat indexpath: indexpath) -> uitableviewcell { switch indexpath.section { case 0: let cell = tableview.dequeuereusablecell(withidentifier: "allgemeineproduktdaten") as! allgemeineproduktdatencell cell.setupallgemeinefields(product: product_obj) return cell case 1: let cell = tableview.dequeuereusablecell(withidentifier: "othercellreuseidentifier") as! othercellclass //set cell content return cell default: return uitableviewcell() } }
Comments
Post a Comment