2017-03-26 207 views
0

准备点击在TableView中一accessoryButton后,它会先功能,然后重定向我PrepareforSegueaccessoryButtonTappedForRowWith功能这在我的代码中创建错误。问题与Segue公司和AccessoryButtonTappedForRowWith

请看看到我的代码:

var indexPathAccessory: Int? 

override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: IndexPath) { 
    indexPathAccessory = indexPath.row 
} 

indexPathAccessory包含其中Accessorybutton被点击的行的值。 第二个功能是:

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "Add" { 
     let nc = segue.destination as! UINavigatorController 
     controller = nc.topViewController as! AVC 
     //Comment 1 
     controller.name = span[indexPathAccessory] 
     //Comment 2 

     controller.delegate = self 
    } 
} 

我点击accessorybutton后得到错误的原因,它是功能,然后再重定向我prepareforSegueaccessoryButtonTappedForRowWith和因值indexPathAccessory哪还没有,我得到这个错误

,才有可能第一个跳accessoryButtonTappedForRowWith得到的indexPathAccessory然后prepareForSegue价值? 如果是,问题将被解决。

我尝试添加一个测试时要返回indexPathAccessory为零。没有错误,但没有以适当的方式 应用程序运行:
我可以看到controller.name等于“测试”,但是当我在AVC视图控制器,成为

有没有建议吗?

回答

0

最后它的工作通过删除accessoryButtonTappedForRowWith功能,并添加以下代码prepareforSegue功能:

 if let indexPath = tableView.indexPath(for: sender as! UITableViewCell) { 

      controller.beamName = "Test" 

      indexSpanAccessory = indexPath.row 
     } 
0

其中一个解决方案可以是 - 从故事板中删除导致控件脱离手的继续,并在您的accessoryButtonTappedForRowWith方法中写入performSegue。

+0

我以前试过,但我没有成功,如何发送的名称和委托给下一个视图控制器! –