text
stringlengths 0
13.4k
|
---|
1. Go to the tableView:cellForRowAtIndexPath: method. |
2. Add the following code just below the line that sets the text label of the cell: |
if (toDoItem.completed) { |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
} else { |
cell.accessoryType = UITableViewCellAccessoryNone; |
} |
Your tableView:cellForRowAtIndexPath: method should now look like this: |
- (UITableViewCell *)tableView:(UITableView *)tableView |
cellForRowAtIndexPath:(NSIndexPath *)indexPath |
{ |
static NSString *CellIdentifier = @"ListPrototypeCell"; |
UITableViewCell *cell = [tableView |
dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath]; |
XYZToDoItem *toDoItem = [self.toDoItems objectAtIndex:indexPath.row]; |
cell.textLabel.text = toDoItem.itemName; |
if (toDoItem.completed) { |
cell.accessoryType = UITableViewCellAccessoryCheckmark; |
} else { |
cell.accessoryType = UITableViewCellAccessoryNone; |
} |
2013-10-22 | Copyright 漏 2013 Apple Inc. All Rights Reserved. |
104 |
Tutorial: Add Data |
Add New Items |
return cell; |
} |
Checkpoint: Run your app. The list of items you added in loadInitialData is visible as cells in your table |
view. When you tap an item, a checkmark should appear next to it. If you tap the same item again, the checkmark |
disappears. |
Add New Items |
The final step in creating the to-do list app鈥檚 functionality is implementing the ability to add an item. When a |
user enters an item name in the text field on the XYZAddToDoItemViewController scene and taps the |
Done button, you want the view controller to create a new list item and pass it back to the |
XYZToDoListViewController to display in the to-do list. |
First, you need to have a list item to configure. Just as with the table view, the view controller is the logical |
place to connect the interface to the model. Give the XYZAddToDoItemViewController a property to hold |
the new to-do item. |
To add an XYZToDoItem to the XYZAddToDoItemViewController class |
1. |
In the project navigator, select XYZAddToDoItemViewController.h. |
Because you鈥檒l need to access the list item from your table view controller later on, it鈥檚 important to make |
this a public property. That鈥檚 why you declare it in the interface file, XYZAddToDoItemViewController.h, |
instead of in the implementation file, XYZAddToDoItemViewController.m. |
2. Add an import declaration to the XYZToDoItem class above the @interface line. |
#import "XYZToDoItem.h" |
3. Add a toDoItem property to the interface. |
@interface XYZAddToDoItemViewController : UIViewController |
@property XYZToDoItem *toDoItem; |
@end |
2013-10-22 | Copyright 漏 2013 Apple Inc. All Rights Reserved. |
105 |
Tutorial: Add Data |
Add New Items |
To get the name of the new item, the view controller needs access to the contents of the text field where the |
user enters the name. To do this, create a connection from the XYZAddToDoItemViewController class that |
connects to the text field in your storyboard. |