ios - Dynamic table view + scroll view -
ios - Dynamic table view + scroll view -
i've got uiscrollview
, on top there info sources , on button there a uitableview
. table view cannot scrolled, capable of displaying big number of cells need manual calculation stuff. that's (you can see in code below). meanwhile, container table view should grow it. seek alter these parameters while loading view nil changes...
this how looks like. in ib.
the struct.
and code.
class viewcontroller: uiviewcontroller, uitableviewdatasource, uitableviewdelegate { @iboutlet var scrollview: uiscrollview! @iboutlet var tableview: uitableview! allow numberofcells = 55 allow rowheight: cgfloat = 40 allow footerheight: cgfloat = 30 allow headerheight: cgfloat = 30 allow identifier = "cell" override func viewdidload() { super.viewdidload() self.tableview.datasource = self self.tableview.delegate = self self.tableview.backgroundcolor = self.view.backgroundcolor self.tableview.scrollenabled = false self.automaticallyadjustsscrollviewinsets = false self.tableview.registerclass(uitableviewcell.self, forcellreuseidentifier: self.identifier) allow estimatedheight = cgfloat(self.numberofcells) * self.rowheight + self.footerheight + self.headerheight self.tableview.frame.size = cgsizemake(self.tableview.bounds.width, estimatedheight) self.scrollview.contentsize = cgsizemake(self.view.bounds.width, cgrectgetmaxy(self.tableview.frame)) self.scrollview.frame.size = cgsizemake(self.view.bounds.width, cgrectgetmaxy(self.tableview.frame)) } // mark:- table view info source func numberofsectionsintableview(tableview: uitableview) -> int { homecoming 1 } func tableview(tableview: uitableview, numberofrowsinsection section: int) -> int { homecoming self.numberofcells } func tableview(tableview: uitableview, cellforrowatindexpath indexpath: nsindexpath) -> uitableviewcell { allow cell = tableview.dequeuereusablecellwithidentifier(self.identifier) uitableviewcell cell.textlabel?.text = "city" cell.accessorytype = uitableviewcellaccessorytype.disclosureindicator homecoming cell } // mark:- table view delegate func tableview(tableview: uitableview, didselectrowatindexpath indexpath: nsindexpath) { tableview.deselectrowatindexpath(indexpath, animated: true) } func tableview(tableview: uitableview, heightforrowatindexpath indexpath: nsindexpath) -> cgfloat { homecoming self.rowheight } func tableview(tableview: uitableview, heightforheaderinsection section: int) -> cgfloat { homecoming self.headerheight } func tableview(tableview: uitableview, heightforfooterinsection section: int) -> cgfloat { homecoming self.footerheight } }
so, reason? how create want? frankly, don't sense quite familiar uiscrollview few tutorials image got constructed.
a uitableview scroll automatically - can't because have set it's height height of of cells. set height screen height , well.
the uiscrollview unnecessary, have done same here - have set scroll view frame height , content height height of table view. setting content height enable scrollview job.
happy coding.
ios swift uiscrollview
Comments
Post a Comment