Adding new items to the Checklist

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



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值