我正在制作一个应用程序,它使用滑动操作将有关单元格内部文本的信息发送到WebViewController。滑动操作是:
let sendToWebsite = UITableViewRowAction(style: .Default, title: "Website")
{ (action, indexPath) in
self.performSegueWithIdentifier("yourSegueIdentifier", sender: nil)
}
sendToWebsite.backgroundColor = UIColor.blueColor()
return [sendToWebsite]
}
这很好但我也有两个segue来自同一个View Controller,另外两个VC。第一个segue(recipeDetail)是直接点击单元格并且工作正常,但是第二个segue(yourSegueIdentifier)是一个按钮,当你在单元格上激活滑动动作并且不起作用时会出现。
segues:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if (segue.identifier == "recipeDetail") {
let indexPath = self.tableView!.indexPathForSelectedRow
let destinationViewController: DetailViewController = segue.destinationViewController as! DetailViewController
destinationViewController.recipe = recipes[indexPath!.row]
}
else if segue.identifier == "yourSegueIdentifier"
{
let indexPath = self.tableView!.indexPathForSelectedRow
let nextVC: WebViewController = segue.destinationViewController as! WebViewController
nextVC.recipe = recipes[indexPath!.row]
}
}
在线
nextVC.recipe = recipes[indexPath!.row]
答案 0 :(得分:1)
看起来在滑动操作上,tableView没有注册“indexPathForSelectedRow”方法。 您可以选择做的是设置全局swipeIndex变量
class ViewController: UIViewController{
var swipeIndex : Int!
//Code, code, code...
然后在调用滑动操作后设置它。
let sendToWebsite = UITableViewRowAction(style: .Default, title: "Website")
{ (action, indexPath) in
self.swipeIndex = indexPath.row
self.performSegueWithIdentifier("yourSegueIdentifier", sender: nil)
}
sendToWebsite.backgroundColor = UIColor.blueColor()
return [sendToWebsite]
}
然后:
else if segue.identifier == "yourSegueIdentifier"
{
let indexPath = self.tableView!.indexPathForSelectedRow
let nextVC: WebViewController = segue.destinationViewController as! WebViewController
nextVC.recipe = recipies[self.swipeIndex]
}
}