Monday, December 16, 2013

iOS7 > Lesson#16 - Single Table View Application

Background

In this lesson, we will learn:

  • Create a single table view application (with Master-Detailed Template)


Step#1 - Create a new project with Master-Detailed Application Template

To create a new Xcode project name "TableView" with a "Master-Detailed Application" template.


Master-Detail Application Template


Save project name as "TableView"
project file structure
default storyboard



Step#2 - Run & Compile


Master scene


Add a new record (row) by clicking the add button "+" in the right of navigation bar


Clicking the Edit button in the left of navigation bar  so that "-" icon will be shown in the left of each record (row)


Clicking the "Delete" button in the right of specific record (row) to confirm the deletion

Step#3 - Storyboard

Change the Master Title in storyboard


Step#4 - Edit xxxMasterViewController.h

TableViewMasterViewController.h


Step#5 - Edit xxxMasterViewController.m


1. To import #import "TableViewDetailViewController.h" in TableViewMasterViewController.m, so that all variable objects declared in Detail class can be viewed in Master class.



2. To declare a NSMutableArray object named "*_objects" in @interface of .m class.

* Notes:
The variable declaration in @interface of .m class is as same as that declared in .h class. The only difference between two ways is no need to code @synthesize in .m class when those variables declared in @interface of .m class and cannot be called by other ViewController classes.

3. To hardcode the array objects inside the method -(void)viewDidLoad of  TableViewMasterViewController.m class.



4. When the table is created, it will return the number of rows in sections from _objects.count.
TableViewMasterViewController.m (numberOfRowsInSection:)


Step#5 - Run & Compile again

Master Scene

Detail Scene

No comments:

Post a Comment