2016-11-21 43 views
0

我嘗試在我的TableView中添加滑動來編輯選項。如果用戶按下編輯,則應該打開一個新的視圖。用editActions和performSegue編輯UITableView行?

但我總是在上線的FUNC「editActionsForRowAt」錯誤使用「如果segue.identifier ==‘ItemDetailsVS {’‘’:致命錯誤:意外發現零而展開的可選值

的SEGUE在故事板的正確名稱。任何想法?

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    if segue.identifier == "ItemDetailsVC" { 
     if let destination = segue.destination as? ItemDetailsViewController { 
      if let item = sender as? Item2 { 
       destination.itemToEdit = item 
      } 
     } 
    } 
} 

func tableView(_ tableView: UITableView, editActionsForRowAt indexPath: IndexPath) -> [UITableViewRowAction]? { 
    let edit = UITableViewRowAction(style: .normal, title: "Edit"){ (action, indexPath) in 

     var segue: UIStoryboardSegue! 

     if segue.identifier == "ItemDetailsVC" { 
      if let objects = self.controller.fetchedObjects , objects.count > 0 { 
       let item = objects[indexPath.row] 
       self.performSegue(withIdentifier: "ItemDetailsVC", sender: item) 
       } 
      } 
     } 
    return [edit] 

} 
+1

你正在創建一個空變量並使用它,當然它會爲你大喊錯誤,你可以參考[this](http://stackoverflow.com/questions/26089152/sending-data-with-segue- with-swift)來學習如何使用segue – Tj3n

回答