MFWalkthrough: A Container View Controller for iOS

The iOS Developer Library has an excellent article on creating custom container view controllers, so I won’t go too much into detail on that. This post will mainly focus on MFWalkthrough, an iOS library I created to simplify the process of sequentially stepping through view controllers.

Consider the use case of gathering information from a user, such as personal data during registration. If the amount of data you’re gathering is relatively small, you may usually get away with placing all inputs in a single view, such as the UITableView form pattern. There are, however, scenarios where it makes to split up the data gathering process across multiple views. Maybe there’s a sequential order to the information you’re gathering with some data depending on other data being valid. Or maybe you have large UI elements that require more space. This is where MFWalkthrough comes in.

MFWalkthrough is designed to be used in conjunction with UINavigationController. You initialize it with the view controllers you’d like to step through and push it onto the navigation stack:

MFWalkthroughViewController *walkthroughController =
      [[MFWalkthroughViewController alloc]
          initWithViewControllers:@[ viewC1, viewC2 ]];

[self.navigationController pushViewController:walkthroughController

The back and continue navigation buttons (powered by FRDLivelyButton) will be rendered and managed by the walkthrough controller:

navigation buttons

Notice how the continue button is rendered as an X. This is because the active view controller has a property whose value is currently false. MFWalkthroughViewController observes this property for changes and animates the continue button accordingly. The property name is provided via a MFWalkthroughDataSource method and can vary per view controller.

To react to events like tapping on the X, transitioning between view controllers, and reaching the beginning (or end) of a walkthrough, you would implement the various MFWalkthroughDelegate methods.

MFWalkthrough is a relatively small library that tries to assume as little as possible. The core principle is to help the developer focus on creating the actual view controllers and not be preoccupied with managing transitions and intermediate states. The next time you’re looking to implement a tutorial or form walkthrough, consider giving MFWalkthrough a try!


Now read this

Temporary Obsessions

Life in short bursts of excitement # My life can essentially be reduced to a series of temporary obsessions. Some last for hours such as a new study in cognitive neuroscience I just learned about from a TED talk. Others may last for... Continue →