还有另一种方法,当我调用选择行时,我可以从refinementslabel.text
获取字符串,因为我认为/显然在新的XCode
调用中
let serviceTypeCell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! ServiceCell
崩溃了我的应用
所以我正在寻找像这样的代码
let text = refinementsLabel.text at indexpath.row
但我不确定要输入什么内容?
let sections = ["All Users & Services","Automotive", "Building & Construction", "Cleaning", "Landscaping & Gardening"]
let services = [["All Users & Services"],["Automotive"],["Air Conditioning & Heating","Bricklaying", "Carpentry","Carpet Layer","Concreting & Paving","Electrical","Fencing and Gates","Flooring","Handyman","Other","Painting & Decorating","Pet Control","Plastering","Plumbing","Roofing","Rubbish Removal","Scaffolding","Tiling"], ["Cleaning"],["Landscaping & Gardening"]]
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let serviceTypeCell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! ServiceCell
var service = serviceTypeCell.refinementsLabel.text
service = services[indexPath.section][indexPath.row]
defaults.set(service, forKey: "Service being searched")
guard let serviceBeingSearched = self.defaults.string(forKey: "Service being searched") else { return }
navigationItem.title = serviceBeingSearched
tableView.reloadData()
}
答案 0 :(得分:0)
如果使用该方法而不是app崩溃,则在创建新单元时使用以下方法正在cellforRow
中使用该方法
let serviceTypeCell = tableView.dequeueReusableCell(withIdentifier: "cellId", for: indexPath) as! ServiceCell
如果您使用didselect
方法获取单元格,则可以使用以下代码
let cell = tableView.cellForRow(at: indexPath) as? ServiceCell
如果从中获取字符串,则可以选择单元格而不是使用下面的行
let service = services[indexPath.section][indexPath.row]