【发布时间】:2016-07-07 20:06:34
【问题描述】:
我正在制作一个应用程序,它使用滑动操作将单元格内的文本信息发送到 WebViewController。滑动动作是:
let sendToWebsite = UITableViewRowAction(style: .Default, title: "Website")
{ (action, indexPath) in
self.performSegueWithIdentifier("yourSegueIdentifier", sender: nil)
}
sendToWebsite.backgroundColor = UIColor.blueColor()
return [sendToWebsite]
}
这很好用,但我也有两个 segues 来自同一个视图控制器,到另外两个 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 返回 nil,可能是因为您的行未处于选中状态。您是否在表格视图上启用了选择?您是否实现了
didSelectRowAtIndexPath委托方法?滑动该行不会自动将其置于选定状态。
标签: swift uitableview null segue exc-bad-instruction