@@ -26,27 +26,8 @@ - (void)viewDidLoad
2626{
2727 [super viewDidLoad ];
2828// Do any additional setup after loading the view, typically from a nib.
29- self.navigationItem .leftBarButtonItem = self.editButtonItem ;
30-
31- UIBarButtonItem *addButton = [[UIBarButtonItem alloc ] initWithBarButtonSystemItem: UIBarButtonSystemItemAdd target: self action: @selector (insertNewObject: )];
32- self.navigationItem .rightBarButtonItem = addButton;
33- }
34-
35- - (void )didReceiveMemoryWarning
36- {
37- [super didReceiveMemoryWarning ];
38- // Dispose of any resources that can be recreated.
3929}
4030
41- - (void )insertNewObject : (id )sender
42- {
43- if (!_objects) {
44- _objects = [[NSMutableArray alloc ] init ];
45- }
46- [_objects insertObject: [NSDate date ] atIndex: 0 ];
47- NSIndexPath *indexPath = [NSIndexPath indexPathForRow: 0 inSection: 0 ];
48- [self .tableView insertRowsAtIndexPaths: @[indexPath] withRowAnimation: UITableViewRowAnimationAutomatic];
49- }
5031
5132#pragma mark - Table View
5233
@@ -69,28 +50,10 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
6950 return cell;
7051}
7152
72- - (BOOL )tableView : (UITableView *)tableView canEditRowAtIndexPath : (NSIndexPath *)indexPath
73- {
74- // Return NO if you do not want the specified item to be editable.
75- return YES ;
76- }
77-
78- - (void )tableView : (UITableView *)tableView commitEditingStyle : (UITableViewCellEditingStyle)editingStyle forRowAtIndexPath : (NSIndexPath *)indexPath
79- {
80- if (editingStyle == UITableViewCellEditingStyleDelete) {
81- [_objects removeObjectAtIndex: indexPath.row];
82- [tableView deleteRowsAtIndexPaths: @[indexPath] withRowAnimation: UITableViewRowAnimationFade];
83- } else if (editingStyle == UITableViewCellEditingStyleInsert) {
84- // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
85- }
86- }
87-
8853- (void )prepareForSegue : (UIStoryboardSegue *)segue sender : (id )sender
8954{
9055 if ([[segue identifier ] isEqualToString: @" showDetail" ]) {
9156 NSIndexPath *indexPath = [self .tableView indexPathForSelectedRow ];
92- NSDate *object = _objects[indexPath.row];
93- [[segue destinationViewController ] setDetailItem: object];
9457 }
9558}
9659
0 commit comments