text stringlengths 0 13.4k |
|---|
undeclared identifier XYZToDoItem.” This means that the compiler doesn’t know about your XYZToDoItem |
when it’s compiling XYZToDoListViewController. Compilers are very particular and need to be told |
explicitly what to pay attention to. |
To tell the compiler to pay attention to your custom list item class |
1. |
Find the #import "XYZToDoListViewController.h" line near the top of the |
XYZToDoListViewController.m file. |
2. Add the following line immediately below it: |
#import "XYZToDoItem.h" |
Checkpoint: Build your project by choosing Product > Build. It should build without errors. |
2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. |
97 |
Tutorial: Add Data |
Display the Data |
Display the Data |
At this point, your table view has a mutable array that’s prepopulated with some sample to-do items. Now you |
need to display the data in the table view. |
You’ll do this by making XYZToDoListViewController a data source of the table view. To make something |
a data source of the table view, it needs to implement the UITableViewDataSource protocol. It turns out |
that the methods you need to implement are exactly the ones you commented out in the second tutorial. To |
have a functioning table view requires three methods. The first of these is numberOfSectionsInTableView:, |
which tells the table view how many sections to display. For this app, you want the table view to display a |
single section, so the implementation is straightforward. |
To display a section in your table |
1. |
2. |
In the project navigator, select XYZToDoListViewController.m. |
If you commented out the table view data source methods in the second tutorial, remove those comment |
markers now. |
3. |
Find the section of the template implementation that looks like this. |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView |
{ |
#warning Potentially incomplete method implementation. |
// Return the number of sections. |
return 0; |
} |
You want a single section, so you want to remove the warning line and change the return value from 0 |
to 1. |
4. Change the numberOfSectionsInTableView: data source method to return a single section, like this: |
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView |
{ |
} |
// Return the number of sections. |
return 1; |
2013-10-22 | Copyright © 2013 Apple Inc. All Rights Reserved. |
98 |
Tutorial: Add Data |
Display the Data |
The next method, tableView:numberOfRowsInSection:, tells the table view how many rows to display |
in a given section. You have a single section in your table, and each to-do item should have its own row in the |
table view. That means that the number of rows should be the number of XYZToDoItem objects in your |
toDoItems array. |
To return the number of rows in your table |
1. |
2. |
In the project navigator, select XYZToDoListViewController.m. |
Find the section of the template implementation that looks like this: |
- (NSInteger)tableView:(UITableView *)tableView |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.