2016-12-07 93 views
0

我在改變segues以顯示或呈現ViewController時遇到了一些問題。 該代碼工作從segues到show/present view controller

override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 
    let noteDetailViewController = segue.destination as! NoteViewController 
    var selectedNote: Note? 

    if segue.identifier == "ShowDetail" { 
     if let selectedNoteCell = sender as? NoteTableViewCell { 
      let indexPath = tableView.indexPath(for: selectedNoteCell)! 
      selectedIndexPath = indexPath 
      if !searchIsEmpty() { 
       selectedNote = filteredNotes[indexPath.row] 
      } else { 
       selectedNote = notes[indexPath.row] 
      } 
     } 
    } else if segue.identifier == "RemindLater" { 
     if let note = notificationNote?.copy() as? Note { 
      selectedNote = note 
     } 
    } 
    noteDetailViewController.note = selectedNote?.copy() as? Note 
    noteDetailViewController.oldNote = selectedNote?.copy() as? Note 
    noteDetailViewController.isFiltered = isFiltered 
    resultSearchController.searchBar.isHidden = true 
} 

呼籲通過

vc.performSegue(withIdentifier: "RemindLater", sender: self) 

我試圖做一個FUNC有異曲同工之妙,但對於使用顯示/本發明的方法。 看起來像這樣

func remindLater() { 
    if let note = notificationNote?.copy() as? Note { 
     noteToEditing = note 
     noteViewController.transitioningDelegate = self 
     noteViewController.modalPresentationStyle = UIModalPresentationStyle.fullScreen 
     noteViewController.modalTransitionStyle = UIModalTransitionStyle.coverVertical 
     noteViewController.note = noteToEditing?.copy() as? Note 
     noteViewController.oldNote = noteToEditing?.copy() as? Note 
     noteViewController.isFiltered = isFiltered 
     resultSearchController.searchBar.isHidden = true 
     present(noteViewController, animated: true, completion: nil) 
     //show(noteViewController, sender: self) 
    } 
} 

但它不起作用。當我在viewDidLoad方法中設置我的視圖控制器上的對象(在調用remindLater方法後),我發現像UIDatePicked和其他所有對象等於零。這不是像使用segue這樣的。我究竟做錯了什麼?

回答

0

從我可以告訴你正在做什麼,聽起來像你需要通過實例化它,然後設置在準備(對於segue:UIStoryboardSegue,發件人:任何?屬性直接。

我可能是關閉基地,但我說的是一樣的東西:

// In a storyboard-based application, you will often want to do a little preparation before navigation 
override func prepare(for segue: UIStoryboardSegue, sender: Any?) { 

    if "RemindLater" == segue.identifier { 

     let controller = segue.destination as! NewViewController 
     controller.note = noteToEditing 
     ... 

    } 

} 
+0

有沒有辦法做到這一點,而不使用賽格瑞方法準備? – L1GhTUA

相關問題