ios - Segue 不执行 iOS8

标签 ios xcode swift ios8 segue

我正在使用 XCode 6,以 iOS 8 为目标并使用 Swift 对其进行编码。

我的 Storyboard Controller 看起来像这样:

Tab Bar > Navigation > Table View > Detail View

Show Detail segue 是从 Table CellDetail View

单击表格单元格时不会触发 prepareForSegue 方法。不过,从按钮到细节的 Segue 效果很好。 didSelectRowAtIndexPath 中的 performSegueWithIdentifier 也可以正常工作。

我还创建了一个全新的测试项目来测试这个问题—— Controller 代码如下所示:

import UIKit

class TestTableController: UITableViewController
{
    override func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int
    {
        return 2;
    }

    override func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell
    {
        let cellId = "testCell";
        var cell: UITableViewCell? = tableView.dequeueReusableCellWithIdentifier(cellId) as? UITableViewCell;

        if (cell == nil)
        {
            cell = UITableViewCell(style: UITableViewCellStyle.Default, reuseIdentifier: cellId);
        }

        cell!.textLabel!.text = "cell \(indexPath.item)";

        return cell!;
    }
}

知道为什么这不能开箱即用吗?

P.S.:当使用 Split View 而不是 Tab Bar 时,相同的 segue 工作正常。

最佳答案

当我使用 tableView.register(AnyClass?, forCellReuseIdentifier: String) 在 ViewDidLoad 方法中注册单元格时,这发生在我身上。当我评论这一行并在 Storyboard 中添加单元格类和单元格标识符时,它开始工作了。同样,如果我在 viewdidload 中取消注释该代码,它将停止工作。

关于ios - Segue 不执行 iOS8,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26504546/

相关文章:

ios - 使用 JSON 中的 NSData 上传多部分图像(HTTP 正文)

ios - React native - Codemagic ios 构建发布失败

iphone - 退出触摸键盘

ios - 添加滤镜时,照片被拉伸(stretch)

快速重新加载数据 UICollectionView

ios - 带有折线或注释的 MapView 在缩放时丢失图 block

ios - 如何将高度约束添加到层次结构中的顶部 UIView?

c++ - Xcode 5.1 针对 C++98 编译,避免 C++11 特性

ios - Xcode:如何修复线程 5:EXC_BREAKPOINT(代码=1,子代码=0x10025c76c)

ios - 如何更改 ios-charts 中的气球标记图像?