OptionViewController.swift: This is the slide menu
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var option : OptionVO
option = viewOptions[indexPath.row]
var nav = UIStoryboard.navigationController(option.identifier)!
var detailController = nav.topViewController as DetailsViewController
detailController.currentView = option.name
self.revealViewController().revealToggleAnimated(true)
}
private extension UIStoryboard {
class func mainStoryboard() -> UIStoryboard { return UIStoryboard(name: "Main", bundle: NSBundle.mainBundle()) }
class func navigationController(identifier : NSString) -> UINavigationController? {
return mainStoryboard().instantiateViewControllerWithIdentifier(identifier) as? UINavigationController
}
And I have a FrontViewController as DetailsViewController.swift. When I select a different view option in the slide panel, I just do revealToggleAnimated() which brings up the FrontViewController.
Now I want to use this new view set for currentView variable in DetailsViewController to change the screen
I want to know what callback is received by DetailsViewController when it is completely shown, so that I can use the newly set currentView variable.
FYI: None of these callbacks are received: viewWillAppear, viewDidAppear, viewDidLoad when revealToggleAnimated() is called.
Solution: Registered for SWRevealViewControllerDelegate:didMoveToPosition and dispatch notification: Here is the final code snippets
OptionViewController.swift [RearViewController]
override func viewDidLoad()
{
self.revealViewController().delegate = self
}
override func tableView(tableView: UITableView, didSelectRowAtIndexPath indexPath: NSIndexPath) {
var option : OptionVO
option = viewOptions[indexPath.row]
currentView = option.name
self.revealViewController().revealToggleAnimated(true)//didMoveToPosition is called when reveal is finished
}
func revealController(revealController: SWRevealViewController!, didMoveToPosition position: FrontViewPosition)
{
var notification = NSNotificationCenter.defaultCenter()
if let myNextView: AnyObject = currentView {
let viewDict = ["view" : myNextView]
notification.postNotificationName("ShowFrontVC",
object: nil,
userInfo: viewDict)
}
}
DetailsViewController.swift [FrontViewController]
func frontVCShown(notification:NSNotification)
{
let userInfo:Dictionary<String,String!> = notification.userInfo as Dictionary<String,String!>
currentView = userInfo["view"]
//change the view for currentView
}