gpt4 book ai didi

ios - 使用未解析的标识符 'cell'

转载 作者:行者123 更新时间:2023-11-29 00:46:34 25 4
gpt4 key购买 nike

我正在一个 View Controller 中创建多个 UITableView,并且我使用以下代码来检查它是哪个 tableView。我不断遇到问题“在最后一行使用未解析的标识符‘cell’。我已经尝试搜索这个,但在 Xcode 7 中没有多少是最新的。请原谅我缺乏术语以及经验,因为我才刚刚开始。请随时问我您可能遇到的任何问题。提前感谢大家花时间阅读本文!

@IBOutlet var tableView1: UITableView!
@IBOutlet var tableView2: UITableView!

// Mens games Variables
var dates = ["7/23", "7/24","7/25","7/26","7/27","7/28","7/29"]
var times = ["7:30","8:00","8:30","9:00","9:30","10:00","10:30"]
var teamsOne = ["VU Reserves 1","VU Reserves 3","VU Reserves 5","VU Reserves 7","VU Reserves 9","VU Reserves 11","VU Reserves 13"]
var teamsTwo = ["VU Reserves 2","VU Reserves 4","VU Reserves 6","VU Reserves 8","VU Reserves 10","VU Reserves 12","VU Reserves 14"]
var fields = ["Turf","Field 1","Field 2","Field 3","Field 4","Field 5","Field 6"]


// Womens games Variables
var womensDates = ["7/23", "7/24","7/25","7/26","7/27","7/28","7/29"]
var womensTimes = ["7:30","8:00","8:30","9:00","9:30","10:00","10:30"]
var womensTeamsOne = ["VU Girls 1","VU Girls 3","VU Girls 5","VU Girls 7","VU Girls 9","VU Girls 11","VU Girls 13"]
var womensTeamsTwo = ["VU Girls 2","VU Girls 4","VU Girls 6","VU Girls 8","VU Girls 10","VU Girls 12","VU Girls 14"]
var womensFields = ["Turf","Field 1","Field 2","Field 3","Field 4","Field 5","Field 6"]




override func viewDidLoad() {
super.viewDidLoad()

tableView1.dataSource = self
tableView1.delegate = self
tableView1.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell1")
tableView2.dataSource = self
tableView2.delegate = self
tableView2.registerClass(UITableViewCell.self, forCellReuseIdentifier: "cell2")
}


func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {


if (tableView == tableView1) {
return teamsOne.count
}
else if (tableView == tableView2) {

return womensTeamsOne.count

} else{

return 0 }

}

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {


if (tableView == tableView1) {

let cell = self.tableView1.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as! gamesCustomCell

cell.date.text = dates[indexPath.row]
cell.time.text = times[indexPath.row]
cell.teamOne.text = teamsOne[indexPath.row]
cell.teamTwo.text = teamsTwo[indexPath.row]
cell.field.text = fields[indexPath.row]

return cell

} else if (tableView == tableView2) {


let cell = self.tableView2.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as! womensGamesCustomCell

cell.womensDate.text = womensDates[indexPath.row]
cell.womensTime.text = womensTimes[indexPath.row]
cell.womensTeamOne.text = womensTeamsOne[indexPath.row]
cell.womensTeamTwo.text = womensTeamsTwo[indexPath.row]

return cell

}

return cell
}
}

最佳答案

只需将 cellForRowAtIndexPath 替换为以下代码

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell:UITableViewCell?

if (tableView == tableView1) {

cell = self.tableView1.dequeueReusableCellWithIdentifier("cell1", forIndexPath: indexPath) as! gamesCustomCell

cell.date.text = dates[indexPath.row]
cell.time.text = times[indexPath.row]
cell.teamOne.text = teamsOne[indexPath.row]
cell.teamTwo.text = teamsTwo[indexPath.row]
cell.field.text = fields[indexPath.row]

}
if (tableView == tableView2) {

cell = self.tableView2.dequeueReusableCellWithIdentifier("cell2", forIndexPath: indexPath) as! womensGamesCustomCell

cell.womensDate.text = womensDates[indexPath.row]
cell.womensTime.text = womensTimes[indexPath.row]
cell.womensTeamOne.text = womensTeamsOne[indexPath.row]
cell.womensTeamTwo.text = womensTeamsTwo[indexPath.row]

}

return cell!
}

关于ios - 使用未解析的标识符 'cell',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38555208/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com