我在更改segues以显示或显示ViewController时遇到了一些问题。 该代码有效
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,但是使用show / present方法。 看起来像这样
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和其他对象等于nil。使用segue不是这样的。我做错了什么?
答案 0 :(得分:0)
从我可以告诉你你想要做什么,听起来你需要通过实例化它然后设置属性来获得对准备中的控制器的引用(对于segue:UIStoryboardSegue,sender:Any?)直接
我可能会离开基地,但我说的是:
// 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
...
}
}