Swift3 发布“准备分段”和“附件”按钮,该按钮随附
单击TableView中的accessoryButton后,它将首先将我重定向到PrepareForsgue函数,然后重定向到accessoryButtonTappedForRowWith函数,该函数会在我的代码中创建错误 请查看我的代码:Swift3 发布“准备分段”和“附件”按钮,该按钮随附,swift3,Swift3,单击TableView中的accessoryButton后,它将首先将我重定向到PrepareForsgue函数,然后重定向到accessoryButtonTappedForRowWith函数,该函数会在我的代码中创建错误 请查看我的代码: var indexPathAccessory: Int? override func tableView(_ tableView: UITableView, accessoryButtonTappedForRowWith indexPath: Inde
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后,我得到了错误原因,它首先将我重定向到prepareforSegue函数,然后重定向到AccessoryButtonTappedForrow,由于indexPathAccessory的值仍然为零,我得到了此错误
是否可以先跳转accessoryButtonTappedForRowWith以获取indexPathAccessory的值,然后再跳转prepareForSegue?
如果是,问题将得到解决
我尝试添加一个测试,以在indexPathAccessory为nil时返回。
应用程序无错误运行,但运行方式不正确:
我可以看到controller.name等于test,但当我在AVC视图控制器上时,name变成了nil
有什么建议吗?解决方案之一是-从情节提要中删除导致控件失控的序列,并在accessoryButtonTappedForRowWith方法中写入性能表。最后,它通过删除accessoryButtonTappedForRowWith函数起作用,并向prepareforSegue函数添加以下代码:
if let indexPath = tableView.indexPath(for: sender as! UITableViewCell) {
controller.beamName = "Test"
indexSpanAccessory = indexPath.row
}
我以前尝试过,但我没有成功如何将名称和委托发送到下一个视图控制器!!!