ios - 更改 UITableViewCell 样式会导致单击操作不会发生

标签 ios swift uitableview view

所以我有一段代码

  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来配置您的单元。要设置具有正确细节的单元格,它应该如下所示......

enter image description here

要在点击时触发到另一个 View Controller 的segue,请从单元格拖动到下一个 View Controller ...

enter image description here

在你的 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/

相关文章:

ios - Swift-在另一个ViewController中的ContainerView中访问UIButton

ios - Xcode MyProjectName-Bridging-Header.h 不存在

ios - 向Realm托管对象添加字符串列表会导致应用在启动时崩溃

ios - -[UITableView reloadData] 仅在滚动后显示变化

iphone - 联系人列表 Action 按钮

ios - 如何从presentingViewController 中模态地呈现ViewController?

ios - 托管对象上下文作为单例?

ios - 使用 AVFoundation 获得裁剪视频的意外结果

ios - 如何组织数据库结构以便能够在其中进行搜索。火力地堡和 swift

ios - 是否可以为 UITableView 静态创建数据?