这是我的代码的一部分。我试图覆盖prepareForSegue,所以当我单击一个单元格时,它可以进入我的另一个视图控制器并根据我单击的单元格显示不同的内容。但我无法覆盖prepareForSegue。
import Foundation
import UIKit
class CategoryListViewController: UIViewController, UITableViewDataSource, UITableViewDelegate
{
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 5
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
let cell:UITableViewCell
cell = tableView.dequeueReusableCellWithIdentifier("firstrow", forIndexPath: indexPath)
cell.textLabel?.text = "test"
cell.detailTextLabel?.text = "try"
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?)
{
switch segue.identifier {
case .Some("DetailSegue"):
let indexPath = tableView.indexPathForSelectedRow!
let viewController = segue.destinationViewController
viewController.navigationItem.title = "Row \(indexPath.row)"
tableView.deselectRowAtIndexPath(indexPath, animated: false)
default:
super.prepareForSegue(segue, sender: sender)
}
}
return cell
}
}
Xcode告诉我override can only be specified on class member
,但我需要override prepareForSegue
。我的代码出了什么问题?这个功能可以在我老师的代码中覆盖,但似乎无法在我的代码中覆盖。
B小心移动代码(命令选项“[”和“]”因为你可以轻松搞砸一个花括号。当所有需要修复一个时,可以通过试图弄清楚你的变量为什么会出现这个错误。打开或关闭支架。
星期六花了5个小时调试,这是一个简单的删除括号 - 与此处相同的错误。