準備點擊在TableView中一accessoryButton後,它會先功能,然後重定向我PrepareforSegue到accessoryButtonTappedForRowWith功能這在我的代碼中創建錯誤。問題與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後得到錯誤的原因,它是功能,然後再重定向我prepareforSegue到accessoryButtonTappedForRowWith和因值indexPathAccessory哪還沒有,我得到這個錯誤
,纔有可能第一個跳accessoryButtonTappedForRowWith得到的indexPathAccessory然後prepareForSegue價值? 如果是,問題將被解決。
我嘗試添加一個測試時要返回indexPathAccessory爲零。沒有錯誤,但沒有以適當的方式 應用程序運行:
我可以看到controller.name等於「測試」,但是當我在AVC視圖控制器,名成爲無
有沒有建議嗎?
我以前試過,但我沒有成功,如何發送的名稱和委託給下一個視圖控制器! –