xxiii PART I MANIPULATING AND DISPLAYING DATA ON THE IPHONE AND IPAD CHAPTER 1 Introducing Data-Driven Applications.. 19 CHAPTER 3 Displaying Your Data: The UITableView.. 89 PART II MA
Trang 3PROFESSIONAL
IPHONE® AND IPAD™ DATABASE
APPLICATION PROGRAMMING
INTRODUCTION xxiii
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
Trang 5
iPhone® and iPad™ Database Application Programming
Trang 6Leave 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
// 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];
Trang 7
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
like Listing 7 - 4
LISTING 7 - 4: EditPriorityController.h
#import < UIKit/UIKit.h >
#import “Task.h”
@interface EditPriorityController : UITableViewController {
continues
FIGURE 7 - 8: EditPriority Controller Screen
Building the Editing Controllers ❘ 185