所以我有一段代码
let cell:UITableViewCell = tableView.dequeueReusableCellWithIdentifier("SampleNameCell")! as UITableViewCell
// cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "SampleNameCell")
第一行代码起作用并创建表格单元格。单击该单元格时,将打开一个与标识符关联的 View 。但是,当我取消注释代码以便可以向单元格添加正确的详细信息标签时,会显示正确的详细信息标签,但现在单击时不会显示 View 。这是造成此问题的未注释代码
cell = UITableViewCell(style: UITableViewCellStyle.Value1, reuseIdentifier: "SampleNameCell")
如有任何帮助,我们将不胜感激,谢谢!
最佳答案
我假设您正在使用 Storyboard来配置您的单元。要设置具有正确细节的单元格,它应该如下所示......
要在点击时触发到另一个 View Controller 的segue,请从单元格拖动到下一个 View Controller ...
在你的 TableView Controller 中,你应该有这样的代码......
override func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell = tableView.dequeueReusableCell(withIdentifier: "SampleNameCell", for: indexPath)
// Configure cell here
return cell
}
请注意方法签名中的 , for: indexPath)
。
关于ios - 更改 UITableViewCell 样式会导致单击操作不会发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42355690/