MonoTouch Navigation Controller Tutorial

This lesson will walk you through the creation of a simple iPhone application that has two views which are navigated between using a Navigation Controller

Generate a new “Navigation-based Project” in MonoDevelop


View the glory of your generated tableview


Run the generated application the simulator. Ooh!

Edit RootViewController.xib.cs to put some data in the table


Click on the RootViewController.xib element in the Solution Explorer and open the RootViewController.xib.cs file. Scroll down to the definition of DataSource : UITableViewSource and change the code in RowsInSection() and GetCell() as displayed above.

Much Better…


Generate a new view controller


Right Click on the NavControllerTutorial project, select “Add…/New File…” and from the iPhone group, select “View Interface Definition with Controller”. Name it “FontListController”

Edit your newly created FontListController.xib.cs


Click on the FontListController.xib and edit FontListController.xib.cs

override ViewDidLoad() so that it replaces the View with a TableView, and then define a private class to supply the data for that table

Add a button to your navigation controller that will instantiate and navigate to your newly defined View


Open RootViewController.xib.cs and modify the ViewDidLoad() method. This is actually where all the action is! When you want to switch between views (in this case, in response to clicking the “Fonts” button), you simply use PushViewController() to put it onto the NavigationController’s stack. Couldn’t be easier, really.

Forward navigation works…


Click on Fonts…

But it’s not obvious that reverse navigation works…


The weird thing here is that if you click on the left-hand side of the navigation bar, you will return to the Fruit Table View. But the navigation is invisible. To change that, you have to set a name for the View in MainWindow.xib

Set the title in the navigation bar of the MainWindow.xib


Bob’s Your Uncle…


2 thoughts on “MonoTouch Navigation Controller Tutorial

  1. Pingback: MonoTouch.Info

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.