我正在使用 XCode 6,以 iOS 8 为目标并使用 Swift 对其进行编码。
我的 Storyboard Controller 看起来像这样:
Tab Bar > Navigation > Table View > Detail View
Show Detail
segue 是从 Table Cell
到 Detail 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/