pp 67
Add a navigation controller
Open a new Add item screen that let the user type the text for items.
- (IBAction)addItem
{
int newRowIndex = [itemscount];
//Create a new Checklist Item and add it to our data model
ChecklistsItem *item = [[ChecklistsItemalloc]init];
item.text =@"the new row";
item.checked = NO;
[items addObject:item];
NSIndexPath *indexPath = [NSIndexPathindexPathForRow:newRowIndexinSection:0];
NSArray *indexPaths = [NSArrayarrayWithObject:indexPath];
[self.tableView insertRowsAtIndexPaths:indexPathswithRowAnimation:UITableViewRowAnimationAutomatic];
}
Table views use index-paths to identify rows.
pp 82 by new screen
Navigation controller
Segue
Table View Controller
Container View Controllers pp95
Apps' main screen consists of ChecklistViewController inside a navigation controller, and the Add Item screen is composed of the AddItemViewController that sits inside its own navigation controller.
The Navigation Controller is a special type of view controller that acts as a container for other view controllers. It comes with a navigation bar that has the ability to easily go from one screen to another. The container essentially "Wrap around" these screens. It's just the frame that contain the view controller that do the real work, which are known as "content" controllers.
- (void)Cancel
{
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
- (void)Done
{
[self.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}
These two method close the front view and go back.The presentingViewController is the left most controller, i.e. the navigation controller. pp94
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
return nil;
}
This is another table view delegate method. When the user taps in a row, the table view sends a delegate willSelectRowAtIndexPath message that says, "Hi, delegate, I am about to select this particular row." By returning nil, our delegate answers, "Sorry, but you are not allowed to!"
a.k.a. Prevent the row from going blue.
GO BACK TO A AND ADD THE ITEM