Understanding ViewControllers

Chapter 7 – View Controllers
To be honest, I quickly jumpted to Chapter 10, since that is the chapter to start working on the Homepwners application.  While only skimming through the previous chapters, I should of spent more time reading Chapter 7 on View Controllers.  So before I continue working on the next chapter on the Homepwners application, I would like to write a blog post on View Controllers.

Most iOS applications will need multiple “screens”.  In iOS development, each screen typically gets its own controller and XIB file.  Each controller has a view that gets placed on the winow.  Thus, we call these controllers, view controllers.  A view controller is a subclass of UIViewController and has an instance variable called, view.  And, we typically need an object to take care of the view swapping for us.  For this chapter, the example application will show the swapping is done by a UITabBarController. 

The iOS example application for this chapter contains two view controllers.  One displays the HypnosisView and the other will let the user get the current time by tapping a button.  The swapping of views uses the UITabBarController.

Now when creating views for the view controllers, there are two ways to do this: create the view programmatically or create a XIB file.  A good rule-of-thumb in deciding when to do one versus the other is if the view has no subviews, create it programmatically.  For Chapter 11 when we added a header control above the UITableView, we created a new viewcontroller and view.  If you remember, we created the view by creating a new XIB file made up of a UIView and 2 UIButtons, Edit and New.  We then made a action connection from each UIButton to the viewcontroller.  We then made a outlet connection from the FileOwner to the UIView control.  Then we load the XIB file manually using NSBundle in the viewcontroller by implementing headerView.  Reminder, XIB files are typically used to create the window and application delegate and to create the view for a view controller.

Chapter 7 helped me understand viewcontrollers much more in depth.  Stay tune for more implementation on the Homepwner class.

iOS development Part 2 – Editing UITableView

In the last blog post and last chapter (Chapter 10) of the Big Nerd Ranch iOS book, I created an application that displays a list of Possession items in a UITableView control.  I will add the source code and any gotchas I went through in that blog post in a little bit.  For this blog post, we will learn how to edit the content (Possession items) in a UITableView.  The UITableView has an editing property which allows you to move, delete and insert rows.  However, editing mode does not allow the user to edit the content of a row, the description property of the Possession item.

When in editing mode, a header view will appear about the UITableView that consists of 2 buttons, Edit and Add buttons.  Tapping the Edit button will toggle the editing mode of the UITableView.  Tapping the Add button will allow you to add a new Possession item to the UITableView.  Along with the 2 buttons in the HeaderView, there will be a delete button to the left of each row in the UITableView.  After this chapter, that will be all for the UITableView control and on to the UINavigationController control.  Stay tuned for an update with source code and gotchas I went through in implementing the edit functionality for the UITableView.

Part 1: UITableView and UITableVIewController

Part 2: Editing UITableView (current)

Part 3: UINavigationController

Part 4: Camera

Part 5: UIPopoverController and Modal View Controllers

Part 6: Saving, Loading and Multitasking

Part 7: Subclassing UITableViewCell

Part 8: Core Data

Part 9: Localization

iOS development Part 1 – UITableView and UITableViewController





I’ve been learning off and on iOS development by reading two main books, Xcode 4 iOS Development Beginner’s Guide (http://www.amazon.com/Xcode-iOS-Development-Beginners-Guide/dp/1849691304) and iOS Programming The Big Nerd Ranch Guide (http://www.amazon.com/iOS-Programming-Ranch-Guides-ebook/dp/B004Z2NQJQ).  I plan to start a series of blog posts to document what I’ve learned and for others to gain insight as well.  So far in reading a little from both books, they each have very simple sample projects to get your feet wet in learning how Xcode IDE is used, writing objective-c code and MVC design pattern.  Today, I’m going to focus on a more complex and realistic sample application that in the Big Nerd Ranch book.

The sample application starts off in Chapter 10, UITableView and UITableViewController, called Homepwner that basically keeps an inventory of all your possessions.  In the case of a fire or other catastrophe, you’ll have a record for your insurance company.  The Homeowner application will grow over the course of 9 chapters in the book.  The first chapter, Chapter 10, will present a list of Possession objects in a UITableView.  So keep coming back to this blog to follow the progression or leave comments if you have a copy of the Big Nerd Ranch and want to develop along with me through the 9 chapters. 

Part 1: UITableView and UITableVIewController (current)

Part 2: Editing UITableView

Part 3: UINavigationController

Part 4: Camera

Part 5: UIPopoverController and Modal View Controllers

Part 6: Saving, Loading and Multitasking

Part 7: Subclassing UITableViewCell

Part 8: Core Data

Part 9: Localization