我正在製作一個應用程序,該應用程序使用滑動動作將單元格內的文本信息發送到WebViewController。滑動的動作是:滑動動作單元格上的不良例外Swift
let sendToWebsite = UITableViewRowAction(style: .Default, title: "Website")
{ (action, indexPath) in
self.performSegueWithIdentifier("yourSegueIdentifier", sender: nil)
}
sendToWebsite.backgroundColor = UIColor.blueColor()
return [sendToWebsite]
}
這工作正常,但我也有兩個賽段來自同一個視圖控制器,以其他兩個VC的。第一個segue(recipeDetail)是當您直接點擊單元格並且工作正常時,但第二個segue(yourSegueIdentifier)是一個按鈕,當您在單元格上激活滑動操作時不會顯示。
的塞格斯:
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]
indexPathForSelectedRow將返回零,可能是因爲你的行不處於選中狀態。你在桌子視圖上選擇了嗎?你是否實現了'didSelectRowAtIndexPath'委託方法?滑動行不會自動將其置於選定狀態。 – SArnab