0

Here is my current setup:

  • CalendarViewController
    • reloadCalendar()
  • SideMenuViewController
    • SideMenuView
      • toggleEventsBtn

Here is some of my code inside SideMenuView:

toggleEventsBtn.addTarget(self, action: "toggleButton:", forControlEvents: .TouchUpInside)
func toggleButton(sender: MenuControlButton!) {
    let shouldShowEvents = sender.shouldShowEvents
    NSUserDefaults.standardUserDefaults().setBool(shouldShowEvents, forKey: "ShowEvents")
}

After this code runs, I need it to call the reloadCalendar method on CalendarViewController. What's the best way to accomplish something like this?

Also, is it bad practice that I'm updating NSUserDefaults from within a UIView?

All help is greatly appreciated :)

Thomas
  • 2,356
  • 7
  • 23
  • 59
  • 1
    create a delegate/protocol in your `CalendarViewController` which will be called in your `toggleEventsBtn` – Rajat Sep 04 '15 at 18:03
  • 1
    I think NSNotificationCenter will do the trick. – Shoaib Sep 04 '15 at 18:04
  • What about the calling of `NSUserDefaults` from within the subview? Is that a bad practice/ should be moved to the ViewController? – Thomas Sep 04 '15 at 18:10
  • And is there a difference/ advantage in me using delegate/protocols over NSNotificationCenter? @Rajatp – Thomas Sep 04 '15 at 18:11
  • 1
    check this - http://stackoverflow.com/questions/1927965/nsnotificationcenter-vs-delegation-using-protocols – Rajat Sep 04 '15 at 18:15

0 Answers0