3

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
}
Imran
  • 769
  • 1
  • 9
  • 21
  • Those are not system methods. You should list any third party frameworks in the subject of your question so people who know those frameworks see the question. Don't make people have to go on a treasure hunt to figure out what you're talking about! – Duncan C May 08 '15 at 20:28
  • @Duncan C, have mentioned under tag. is it not enough? – Imran May 08 '15 at 20:32
  • Nope. Much better to put it in the subject of your post. – Duncan C May 08 '15 at 20:33
  • To be honest I didn't even look at your tags, so I was pretty confused about you question – Duncan C May 08 '15 at 20:33

1 Answers1

0

If I understood your question right, I suggest sending a NSNotification yourself. I'm going to assume that you're using tableView for your RearViewController.

In your RearViewController

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    [[NSNotificationCenter defaultCenter] postNotificationName:@"ShowFrontVC" object:nil userInfo:nil];
}

In your FrontViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Add observer
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(frontVCShown) name:@"ShowFrontVC" object:nil];
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    // Remove Observer
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

- (void)frontVCShown {
    // Update your view controller
}
SFF
  • 877
  • 2
  • 11
  • 26