Skip to content

INTERNALS: What happens when...

klazuka edited this page Sep 13, 2010 · 2 revisions

What happens when the user taps a day on the calendar?

  1. KalGridView will receive the touch events in its touches{Began:,Moved:,Ended:}withEvent: handlers.
  2. KalGridView marks the tile as selected, which in turn:
    1. tells KalTileView that it needs to redraw itself.
    2. tells the delegate that a new date has been selected. The delegate will then tell the dataSource to update the list of data from which it configures UITableViewCells.
  3. When the touch event finishes, KalGridView will decide to do one of 3 things:
    1. If the finger was released over a tile that belongs to an adjacent month, it will tell the delegate to show the adjacent month
    2. If the finger was released over any other type of tile, it will just mark the tile as selected. Once again triggering the side effects of Step #2.
    3. If the finger was released anywhere else on the screen, it will do nothing.

What happens when the user slides the calendar to the next month?

The first thing to understand is that KalGridView double-buffers the views that represent the grid of tiles (KalMonthView). So there is both a “frontMonthView” and a “backMonthView.” The frontMonthView pointer always points at the view that is being displayed on-screen. For more details about how KalMonthView is double-buffered, see INTERNALS: KalGridView and KalMonthView.

Assume that the user tapped the right arrow image at the top of the calendar.

  1. KalView tells its delegate, KalViewController, to showFollowingMonth
  2. KalViewController responds by doing 3 things
    1. Updates the model state (KalLogic) to reflect the following month.
    2. Asynchronously tells its dataSource that it will be presenting the date range of visible dates in the following month.
      1. The dataSource loads its application data for that date range and issues a callback to KalViewController when the data is ready.
    3. Tells KalView to slideUp, resulting in the following steps:
      1. KalView will receive the slideUp message and will pass it along to KalGridView.
      2. KalGridView reconfigures the off-screen backMonthView so that its contents reflect the month that is about to slide on-screen.
      3. KalGridView then moves backMonthView either above or below frontMonthView (depending on the slide direction).
      4. Next, KalGridView tells Core Animation that it wants to slide both the frontMonthView and the backMonthView such that backMonthView will be entirely on-screen.
      5. Just before the animation is triggered, KalGridView swaps the frontMonthView and backMonthView pointers (“flips the buffers”)
      6. Finally, Core Animation runs the animation.