ffirs.indd ii
9/17/10 6:52:52 PM
PROFESSIONAL
IPHONE® AND IPAD™ DATABASE
APPLICATION PROGRAMMING
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xxiii
Download from Wow! eBook <www.wowebook.com>
PART I
MANIPULATING AND DISPLAYING DATA
ON THE IPHONE AND IPAD
CHAPTER 1
Introducing Data-Driven Applications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
CHAPTER 2
The iPhone and iPad Database: SQLite . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
CHAPTER 3
Displaying Your Data: The UITableView . . . . . . . . . . . . . . . . . . . . . . . . . . 57
CHAPTER 4
iPad Interface Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
PART II
MANAGING YOUR DATA WITH CORE DATA
CHAPTER 5
Introducing Core Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
CHAPTER 6
Modeling Data in Xcode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 145
CHAPTER 7
Building a Core Data Application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
CHAPTER 8
Core Data–Related Cocoa Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 219
CHAPTER 9
Core Data Migration and Performance . . . . . . . . . . . . . . . . . . . . . . . . . . 235
PART III
APPLICATION INTEGRATION USING WEB SERVICES
CHAPTER 10
Working with XML on the iPhone . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 271
CHAPTER 11
Integrating with Web Services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 301
APPENDIX A
Tools for Troubleshooting Your Applications . . . . . . . . . . . . . . . . . . . . . 343
INDEX . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 355
ffirs.indd i
9/17/10 6:52:51 PM
ffirs.indd ii
9/17/10 6:52:52 PM
Download from Wow! eBook <www.wowebook.com>
PROFESSIONAL
Download from Wow! eBook <www.wowebook.com>
iPhone® and iPad™ Database
Application Programming
ffirs.indd iii
9/17/10 6:52:53 PM
184
❘
CHAPTER 7 BUILDING A CORE DATA APPLICATION
Leave the numberOfSectionsInTableView method with the default implementation. The table
will have only one section. Change the tableView:numberOfRowsInSection: method to return
one row:
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
return 1;
}
// Customize the number of rows in the table view.
- (NSInteger)tableView:(UITableView *)tableView
numberOfRowsInSection:(NSInteger)section {
return 1;
}
EditTextController.m
Next, you should implement the tableView:cellForRowAtIndexPath: method to show the
textField in the tableView cell:
// Customize the appearance of table view cells.
- (UITableViewCell *)tableView:(UITableView *)tableView
cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *CellIdentifier = @”Cell”;
UITableViewCell *cell =
[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (cell == nil) {
cell = [[[UITableViewCell alloc]
initWithStyle:UITableViewCellStyleDefault
reuseIdentifier:CellIdentifier] autorelease];
}
// Set up the cell...
if (indexPath.row == 0)
{
UIView* cv = cell.contentView;
[cv addSubview:textField];
}
return cell;
}
EditTextController.m
CH007.indd 184
9/18/10 9:48:44 AM
Building the Editing Controllers
❘ 185
Implement tableView:didSelectRowAtIndexPath: to deselect the selected cell. You don’t
necessarily have to do this to complete the functionality of your application, but the Apple Human
Interface Guidelines suggest that you deselect a tableview cell after its selection. Therefore, I ’m
including the following code:
- (void)tableView:(UITableView *)tableView
didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
// Deselect the currently selected row according to the HIG
[tableView deselectRowAtIndexPath:indexPath animated:NO];
}
EditTextController.m
Last, but not least, you need to implement the dealloc method to clean up any memory that your
class has allocated:
- (void)dealloc {
[managedObject release];
[managedObjectContext release];
[keyString release];
[super dealloc];
}
EditTextController.m
Setting Priorities with the
EditPriorityController
The EditPriorityController screen, which you can see in Figure
7-8, allows the user to choose the priority for a task. Again, you
will implement the screen as a TableView. This time, there will
be a row for each priority level. In the Sub Controllers group,
create a new UITableviewController without a NIB called
EditPriorityController.
In the header fi le, you will need to add instance variables and
properties for a Task object and the context. You will also need to add
a #import directive for the Task.h header fi le. Your header should look
like Listing 7- 4.
LISTING 7-4: EditPriorityController.h
#import <UIKit/UIKit.h>
#import “Task.h”
FIGURE 7-8: EditPriority
Controller Screen
@interface EditPriorityController : UITableViewController {
continues
CH007.indd 185
9/18/10 9:48:44 AM