Import UIKit
Class Viewcontroller:uitableviewcontroller {
OverrideFuncViewdidload() {Super.viewdidload ()Set data source and proxy Tableview.datasource =Self tableview.delegate =SelfSet the Reuse ID Tableview.registerclass (Uitableviewcell.classforcoder (), Forcellreuseidentifier:"Cell")}OverrideFuncTableView(Tableview:uitableview, Heightforrowatindexpath Indexpath:nsindexpath)CGFloat {Return80}OverrideFuncDidreceivememorywarning() {Super.didreceivememorywarning ()Dispose of any resources the can be recreated.}OverrideFuncNumberofsectionsintableview(Tableview:uitableview)Int {Return5}OverrideFuncTableView(Tableview:uitableview, Numberofrowsinsection section:int)Int { return 4}//proxy set celloverride func tableView(Tableview:uitableview, Cellforrowatindexpath indexpath:nsindexpath), UITableViewCell {let cell = Tableview.dequeuereusablecellwithidentifier ("cell", forindexpath:indexpath) Cell.backgroundcolor = Uicolor.bluecolor () Cell.textlabel? Text = "Hello\ (indexpath.row)" //Set some properties of cell ... return cell}
}
or refer to the code below
Import UIKit
Class Minecentercell:uitableviewcell {
VarTitlestring:String?var iconimagename:String?VarTitlelabel:UILabel?var Iconimageview:Uiimageview?OverrideInit (style:Uitableviewcellstyle, Reuseidentifier:String?) {Super.Init (Style:style, Reuseidentifier:reuseidentifier)self.iconimageview=Uiimageview ()Self.contentView.addSubview (self.iconimageview!)Self.Titlelabel=UILabel ()Self.contentView.addSubview (Self.titlelabel!) Setupviews ()}requiredInit? (Coder Adecoder:Nscoder) {FatalError ("Init (coder:) have not been implemented")}FuncSetupviews() {IfSelf.iconimagename! =Nil {Self.iconimageview?. Image=UIImage (named:iconimagename!)Self.Titlelabel?. text=Self.Titlestring}Self.iconimageview?. Snp_makeconstraints (closure: {make)In Make.top.equalTo () Make.bottom.equalTo (-(ten) make.Left.equalto (5) Make.width.equalTo (self.iconimageview!. Snp_height)})Self.Titlelabel?. Snp_makeconstraints (closure: {make)In make.Left.equalto (self.iconimageview!. snp_right). Offset (Ten) Make.centerY.equalTo (self.iconimageview!. snp_centery)})}override func awakefromnib() { super.awakefromnib () //initialization code}override Func layoutsubviews() { super.layoutsubviews () setupviews ()}override func setselected (Selected:bool, Animated:bool) { super.setselected (selected, animated:animated) //Configure the view fo R the selected state}
}
Func TableView (Tableview:uitableview, Cellforrowatindexpath indexpath:nsindexpath), uitableviewcell{
If indexpath.section = = 0 {
Let cell = Mineinfocell.cellwithtableview (TableView)
Cell.delegate=self
return cell
}
Let Indentifier ="Minecentercell"var cell:minecentercell! = Tableview.dequeuereusablecellwithidentifier (Indentifier)As?Minecentercellif cell = =Nil {cell=Minecentercell (style:.Default, Reuseidentifier:indentifier)}let images = [["Ji-fen"],["ZB proposal","ZB Investment Policy","ZB self-study camp"],["ZB team Management","ZB Performance Management","ZB Attendance"],["Zbappshare", "zbsetting"] let titles = [[" my points: \ ( USERINFO.sharedInstance.getpoint ()) "],[" My proposal ", " My insurance sheet ", Span class= "hljs-string" > "self-study camp"],[ "team Management", "performance management", " My attendance "],[" Share App "" settings "] if indexpath.section = = 1 {cell?. Accessorytype =. disclosureindicator} cell?. Iconimagename=images[indexpath.section-1][indexpath.row] cell. Titlestring=titles[indexpath.section-1][indexpath.row] Return cell!}
Pure code creation in Swift Tableviewcell