DestinationViewController Segue and UINavigationController swift
You only need to access the navigation controller's topViewController, which will be the AddEventViewController. Here is the code:
override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
if segue.identifier == "fromEventTableToAddEvent" {
let nav = segue.destinationViewController as! UINavigationController
let addEventViewController = nav.topViewController as! AddEventViewController
addEventViewController.newTagArray = newTagArray
}
}
SWIFT 3: Segue with navigation controller
For the first Problem, When using embedded in navigation controller you have don't have to create action function when the button is tapped. Navigation controller does it for you. So things you need to do :
- Disconnect the function
btnTapped
from the button using storyBoard. - Delete or comment the function
btnTapped
(You don't need it).
Set data in `prepareForSegue` with navigation controller
In prepareForSegue
access the target navigation controller, and then its top:
let destinationNavigationController = segue.destination as! UINavigationController
let targetController = destinationNavigationController.topViewController
From the target controller you can access its view and pass data.
In old - now obsolete - versions of Swift and UIKit the code was slightly different:
let destinationNavigationController = segue.destinationViewController as UINavigationController
let targetController = destinationNavigationController.topViewController
Passing data with segue through navigationController
The destination view controller of the segue is the UINavigationController
. You need to ask it for its top view controller to get to the real destination view controller:
override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
if segue.identifier == "showItemSegue" {
let navController = segue.destination as! UINavigationController
let detailController = navController.topViewController as! ShowItemViewController
detailController.currentId = nextId!
}
}
Related Topics
Xcode 8.1 Push Notifications in Swift 2.3 with Firebase Integration Not Getting
iOS 8 Uiactivityviewcontroller and Uialertcontroller Button Text Color Uses Window's Tintcolor
Hardware-Dependent Nsdateformatter Datefromstring: Bug (Returns Nil)
Swift - Error 'Expected ',' Separator' and 'Expected Expression in List of Expressions'
Swiftui Generic Pull to Refresh View
Alternative to Usernotificationcenterdelegate's Willpresent When App Is in Background
How to Send Multiple Parameterts to PHP Server in Http Post
Is Possible to Simulate Touch Event Using an External Keyboard on iOS Jailbroken
This Class Is Not Key Value Coding-Compliant for the Key Xxxxxx
Error: Uicollectionview Must Be Initialized with a Non-Nil Layout Parameter
How to Draw a Line in the Simplest Way in Swift
Uitableview Reloaddata Automatically Calls Resignfirstresponder
Xcode 6 Standard Architectures Exclude Armv7S
Xcode 6 Upload App with Error: Itunes Store Operation Failed Error Description Not Available