[英]performSegueWithIdentifier doesn't work - Swift
Im trying to use performSegueWithIdentifier when user taps in a row of a table view. 我试图在用户点击表视图的一行时使用performSegueWithIdentifier。 How ever, it doesn't work and i have the next error:
但是,它不起作用,并且下一个错误是:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Could not perform segue with identifier 'categoriesS'. A segue must either have a performHandler or it must override -perform.'
I googled the error, but i don't find anything. 我用错误搜索了一下,但是什么也没找到。 I've already create the push segues in the storyboard and set them the identifiers that I use in my code.
我已经在情节提要中创建了推送脚本,并为它们设置了我在代码中使用的标识符。 This is my code(PD: Im using this tableview, as a side bar menu):
这是我的代码(PD:我使用此表视图作为侧边栏菜单):
import Foundation
class menuVC: UIViewController,UITableViewDelegate, UITableViewDataSource {
@IBOutlet weak var ProfileImage: UIImageView!
@IBOutlet weak var myTable: UITableView!
var opciones = [String]()
var segues = [String]()
override func viewDidLoad() {
super.viewDidLoad()
myTable.delegate = self
opciones = ["Categories","My Coins","Get Coins","Share","LogOff","Exit"]
segues = ["categoriesS","myCoinsS","getCoinsS"]
}
func tableView(tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return 6
}
func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
print(opciones[indexPath.row])
self.performSegueWithIdentifier(segues[indexPath.row], sender: self)
}
func numberOfSectionsInTableView(tableView: UITableView) -> Int {
return 1
}
func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell {
var cell = tableView.dequeueReusableCellWithIdentifier("cell", forIndexPath: indexPath) as UITableViewCell
cell.textLabel?.text = opciones[indexPath.row]
return cell
}
}
Thanks! 谢谢!
You have given a wrong segue as console clearly stated that. 您输入了错误的命令,因为控制台明确指出了这一点。 You are looking for '
categoriesS
' which is in ' segue
' array, but you are passing from ' opciones
' array. 您正在寻找“
categoriesS
”这是在“ segue
”数组,但你是从“传递opciones
”阵列。 Look closely. 仔细看。
Edit I saw your edit, looks like u have populate your table using different array, but u have used other array in didselectrow.please check it 编辑我看到了您的编辑,看起来您已使用其他数组填充了表格,但是您在didselectrow中使用了其他数组。请检查一下
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.