2015-03-02 71 views
2

我有一個addViewController和一個UITableViewcontroller,我試圖在我的UITableViewCell中添加一個滑動編輯選項,它將直接去addViewController進行編輯。編輯UITableView行項目swift

錯誤:致命錯誤:意外發現零,同時展開指着這條線 enter image description here

我的UITableViewController內的可選值

override func tableView(tableView: UITableView, editActionsForRowAtIndexPath indexPath: NSIndexPath) -> [AnyObject]? { 
     var editNotesAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Edit") { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in 

      //methods 
      self.performSegueWithIdentifier("editNoteSegue", sender: nil) 

      var segue: UIStoryboardSegue! 
      if segue.identifier! == "editNoteSegue" { 

       var selectedItem: NSManagedObject = self.notesList[self.tableView.indexPathForSelectedRow()!.row] as NSManagedObject 
       let IVC: AddNoteViewController = segue.destinationViewController as AddNoteViewController 

       IVC.notes = selectedItem.valueForKey("notes") as String 
       IVC.existingItem = selectedItem 

      } 


     } 

     //change the background color of the swipe-to-edit 
     //editNotesAction.backgroundColor = UIColor.greenColor() 
     editNotesAction.backgroundColor = UIColor(patternImage: UIImage(named: "editBG")!) 

     var deleteNotesAction = UITableViewRowAction(style: UITableViewRowActionStyle.Default, title: "Delete") { (action:UITableViewRowAction!, indexPath:NSIndexPath!) -> Void in 

      var appDel: AppDelegate = UIApplication.sharedApplication().delegate as AppDelegate 
      var context: NSManagedObjectContext = appDel.managedObjectContext! 

      if let tv = tableView as UITableView? { 
        context.deleteObject(self.notesList[indexPath.row] as NSManagedObject) 
        self.notesList.removeAtIndex(indexPath.row) 
        tv.deleteRowsAtIndexPaths([indexPath], withRowAnimation: UITableViewRowAnimation.Fade) 
        tableView.reloadData() 
      } 

     } 

     return [editNotesAction, deleteNotesAction] 
    } 

編輯: enter image description here

EDIT2: 剛要清楚,我想要編輯(以編程方式添加),當點擊時,它會去新的筆記視圖控制器。

enter image description here

回答

3

你忘了Storyboard Unwind Segue來命名它。

enter image description here

你可以在這裏找到它。

enter image description here

P.S:您需要分配出口物體像這樣的創造Unwind Segue

enter image description here

+0

我在哪裏可以找到它?在我的tableviewcontroller或viewcnotroller – shaideru 2015-03-02 08:10:40

+0

檢查我編輯的答案 – 2015-03-02 08:12:53

+0

我編輯我的問題,我仍然無法找到它。 – shaideru 2015-03-02 08:16:29