Ios 如何通过使用多个自定义类来使用多个TableView
我在那里有xib文件,我使用多个自定义xib单元格创建多个表,但在加载多个自定义单元格时遇到了问题。我在indexpath的单元格行代码上出错…我不知道如何使用多个自定义单元格的多个tableview来执行此操作 有人帮我解决这个问题吗 提前谢谢Ios 如何通过使用多个自定义类来使用多个TableView,ios,swift,uitableview,Ios,Swift,Uitableview,我在那里有xib文件,我使用多个自定义xib单元格创建多个表,但在加载多个自定义单元格时遇到了问题。我在indexpath的单元格行代码上出错…我不知道如何使用多个自定义单元格的多个tableview来执行此操作 有人帮我解决这个问题吗 提前谢谢 func TablecellRegisternib() { self.Hight_table.register(UINib(nibName: "tableviewcellTableViewCell", bundle: nil), for
func TablecellRegisternib() {
self.Hight_table.register(UINib(nibName: "tableviewcellTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
self.weight_table.register(UINib(nibName: "tableviewcellTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
self.Gender_table.register(UINib(nibName: "tableviewcellTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
self.Weekday_table.register(UINib(nibName: "tableviewcellTableViewCell", bundle: nil), forCellReuseIdentifier: "cell")
self.Gym_tableview.register(UINib(nibName: "GymTableCell", bundle: nil), forCellReuseIdentifier: "cell1")
self.Sports_tableview.register(UINib(nibName: "SpotsTableCell", bundle: nil), forCellReuseIdentifier: "cell2")
self.AdditioanlSports_tableview.register(UINib(nibName: "AdditioanlSpotsTableCell", bundle: nil), forCellReuseIdentifier: "cell3")
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
// Return the number of items in the sample data structure.
var count:Int?
if tableView == self.weight_table {
count = WightUnitArray.count
}
if tableView == self.Hight_table {
count = HightUnitArray.count
}
if tableView == self.Weekday_table {
count = WeekdayArray.count
}
if tableView == self.Gender_table {
count = GenderArray.count
}
if tableView == self.Sports_tableview {
count = SportsArray.count
}
if tableView == self.AdditionalSports_tableview {
count = AdditionalSportsArray.count
}
return count!
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
if tableView == self.weight_table {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! tableviewcellTableViewCell
cell.detail_lbl.text=WightUnitArray[indexPath.row]
cell.selectionStyle = UITableViewCellSelectionStyle.none;
cell.detail_lbl.font = UIFont(name:"Roboto-Regular", size:13)
cell.detail_lbl.adjustsFontSizeToFitWidth = true
if (selectedIndex == indexPath as NSIndexPath?) {
cell.radi_btn.setImage(UIImage(named: "radio_btn_active.png"),for:UIControlState.normal)
} else {
cell.radi_btn.setImage(UIImage(named: "radio_btn.png"),for:UIControlState.normal)
}
}
if tableView == self.Hight_table {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! tableviewcellTableViewCell
cell.detail_lbl.text=HightUnitArray[indexPath.row]
cell.selectionStyle = UITableViewCellSelectionStyle.none;
cell.detail_lbl.font = UIFont(name:"Roboto-Regular", size:13)
cell.detail_lbl.adjustsFontSizeToFitWidth = true
if (selectedIndex == indexPath as NSIndexPath?) {
cell.radi_btn.setImage(UIImage(named: "radio_btn_active.png"),for:UIControlState.normal)
} else {
cell.radi_btn.setImage(UIImage(named: "radio_btn.png"),for:UIControlState.normal)
}
}
if tableView == self.Weekday_table {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! tableviewcellTableViewCell
cell.detail_lbl.text=WeekdayArray[indexPath.row]
cell.selectionStyle = UITableViewCellSelectionStyle.none;
cell.detail_lbl.font = UIFont(name:"Roboto-Regular", size:13)
cell.detail_lbl.adjustsFontSizeToFitWidth = true
if (selectedIndex == indexPath as NSIndexPath?) {
cell.radi_btn.setImage(UIImage(named: "radio_btn_active.png"),for:UIControlState.normal)
} else {
cell.radi_btn.setImage(UIImage(named: "radio_btn.png"),for:UIControlState.normal)
}
}
if tableView == self.Gender_table {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell") as! tableviewcellTableViewCell
cell.detail_lbl.text=GenderArray[indexPath.row]
cell.selectionStyle = UITableViewCellSelectionStyle.none;
cell.detail_lbl.font = UIFont(name:"Roboto-Regular", size:13)
cell.detail_lbl.adjustsFontSizeToFitWidth = true
if (selectedIndex == indexPath as NSIndexPath?) {
cell.radi_btn.setImage(UIImage(named: "radio_btn_active.png"),for:UIControlState.normal)
} else {
cell.radi_btn.setImage(UIImage(named: "radio_btn.png"),for:UIControlState.normal)
}
}
if tableView == self.Gym_tableview {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell1") as! GymTableCell
var GymDict = GymtableArray[indexPath.row]
cell.sportlbl!.text = GymDict["name"] as? String
cell.sportlbl?.adjustsFontSizeToFitWidth = true
cell.sportlbl?.font = UIFont(name:"Roboto-Regular", size:13)
return cell
}
if tableView == self.Sports_tableview {
let cell = tableView.dequeueReusableCell(withIdentifier: "cell3") as! SportsTableCell
var SportsDict = SportsArray[indexPath.row]
cell.sportlbl1!.text = SportsDict["name"] as? String
cell.sportlbl1?.adjustsFontSizeToFitWidth = true
cell.sportlbl1?.font = UIFont(name:"Roboto-Regular", size:13)
return cell
}
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if tableView == self.weight_table {
tableView.deselectRow(at: indexPath as IndexPath, animated: true)
let row = indexPath.row
selectedIndex = indexPath as NSIndexPath?
let weightstring = (WightUnitArray[row])
if( weightstring != "Pound")
{
self.WeightUnitTabletxt.text = "kg"
}
else{
self.WeightUnitTabletxt.text = "lbs"
}
self.Weight_View.isHidden = true
tableView.reloadData()
}
if tableView == self.Hight_table {
tableView.deselectRow(at: indexPath as IndexPath, animated: true)
let row = indexPath.row
selectedIndex = indexPath as NSIndexPath?
let Hightstr = (HightUnitArray[row])
if( Hightstr != "Feet")
{
self.HeightUnitTabletxt.text = "m"
}
else{
self.HeightUnitTabletxt.text = "ft"
}
self.Hight_view.isHidden = true
tableView.reloadData()
}
if tableView == self.Weekday_table {
tableView.deselectRow(at: indexPath as IndexPath, animated: true)
let row = indexPath.row
selectedIndex = indexPath as NSIndexPath?
self.FirstDayofWeek_txt.text = (WeekdayArray[row])
self.FirstdayoftheWeek_view.isHidden = true
tableView.reloadData()
}
if tableView == self.Gender_table {
tableView.deselectRow(at: indexPath as IndexPath, animated: true)
let row = indexPath.row
selectedIndex = indexPath as NSIndexPath?
self.gender_txt.text = (GenderArray[row])
self.Genderview.isHidden = true
tableView.reloadData()
}
}
你到底有什么问题?我无法加载数据…我是swift开发的新手。如何使用多个自定义单元格执行多表视图您的代码流似乎设置正确,您所说的问题是什么?
我在indexpath中的单元格行代码出现错误。
您能说明一下您遇到的错误吗?func tableView(utableview:UITableView,cellForRowAt indexpath:indexpath)->UITableViewCell{}返回单元格}