-
Notifications
You must be signed in to change notification settings - Fork 0
/
ADDNotesViewController.m
96 lines (61 loc) · 2.61 KB
/
ADDNotesViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// ADDNotesViewController.m
// Everpobre
//
// Created by Alejandro Delgado Diaz on 02/11/13.
// Copyright (c) 2013 Alejandro Delgado Diaz. All rights reserved.
//
#import "ADDNotesViewController.h"
#import "AGTnote.h"
#import "ADDNoteViewController.h"
@interface ADDNotesViewController ()
@property (strong, nonatomic) AGTnoteBook *notebook;
@end
@implementation ADDNotesViewController
- (id) initWithFetchedResultsController:(NSFetchedResultsController *)aFetchedResultsController style:(UITableViewStyle)aStyle notebook: (AGTnoteBook *) aNoteBook{
if (self = [super initWithFetchedResultsController:aFetchedResultsController style:aStyle]) {
_notebook = aNoteBook;
}
return self;
}
- (void) viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
UIBarButtonItem *btn = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNote:)];
self.navigationItem.rightBarButtonItem = btn;
}
- (void) addNote:(UIBarButtonItem *) sender{
AGTnote *note = [AGTnote noteWithName:@"New Note" notebook:self.notebook inContext:self.notebook.managedObjectContext];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (UITableViewCell *) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//averiguar la nota
AGTnote *note = [self.fetchedResultsController objectAtIndexPath:indexPath];
//obtener una celda
static NSString *cellId = @"cellId";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellId];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleSubtitle
reuseIdentifier:cellId];
}
//sincronizar la celda
cell.textLabel.text = note.name;
cell.imageView.image = note.photo;
NSDateFormatter *fmt = [[NSDateFormatter alloc]init];
fmt.dateStyle = NSDateFormatterMediumStyle;
cell.detailTextLabel.text = [fmt stringFromDate:note.modifyDate];
return cell;
}
#pragma mark - tableView Delegate
-(void) tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
//averiguar la nota
AGTnote *note = [self.fetchedResultsController objectAtIndexPath:indexPath];
//crear el controlador de la nota
ADDNoteViewController *noteVC= [[ADDNoteViewController alloc]initWithModel: note];
//hacer un push
[self.navigationController pushViewController:noteVC animated:YES];
}
@end