swift - 当我从 Nib 加载单元格时,UITableViewCell 会转到详细 View 吗?

标签 swift interface-builder segue

我有一个 custom cell class 和一个包含该 cell 设计的 custom nib。在我的 storyboard 中,我没有看到将 tableview 连接为 segue 的方法(就像你对原型(prototype)单元格所做的那样)我从那以后就有了我的单元格是通过 tableView:cellForRowAtIndexPath 添加的。

有没有办法连接这个 segue,这样我就可以继续使用 Storyboard将单元格连接到详细 View Controller ?

这是我的 tableView:cellForRowAtIndexPath 代码:

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
    var cell = tableView.dequeueReusableCellWithIdentifier("cell") as MyTableViewCell?

    if (cell == nil) {
        tableView.registerNib(UINib(nibName: "MyTableViewCell", bundle: NSBundle(identifier: "com.company.InterfaceComponents")), forCellReuseIdentifier: "cell")
        cell = tableView.dequeueReusableCellWithIdentifier("cell") as MyTableViewCell?
    }

    return cell!
}

最佳答案

我发现我可以做的是添加一个手动转场(通过从 Controller 拖动)到详细信息 Controller (如使用标识符显示转场:“showDetails”)。然后我可以在我的 TableView 中添加以下代码:

func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
    self.performSegueWithIdentifier("showDetails", sender: tableView)
}

这会给我想要的功能。

关于swift - 当我从 Nib 加载单元格时,UITableViewCell 会转到详细 View 吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26378210/

相关文章:

ios - 为不同设备获取相同的 uibutton 中心值

swift - 在 Swift 中从类创建 JSON 对象

ios - 如何将图像放在 Swift 的 UIImageView 上?

名称与类不同的 Swift 初始值设定项?

ios - 如何实现一个(几乎)全 View uitableview 可以滚动到最后一个单元格并在 iOS 中显示更多元素

ios - 停止推送 segue 直到被告知继续前进 - Obj C

ios - 如何在 iOS swift 中对多个按钮使用相同的 segue?

iphone - iPhone 界面生成器中的分发选项

ios - 如何调整单元格的高度以便内容可以适合它?

ios - 展开 segue 不展开