-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathNotesListViewController.m
More file actions
executable file
·82 lines (64 loc) · 2.3 KB
/
Copy pathNotesListViewController.m
File metadata and controls
executable file
·82 lines (64 loc) · 2.3 KB
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
//
// CETableViewController.m
// TextKitNotepad
//
// Created by Colin Eberhardt on 19/06/2013.
// Copyright (c) 2013 Colin Eberhardt. All rights reserved.
//
#import "NotesListViewController.h"
#import "AppDelegate.h"
#import "Note.h"
#import "NoteEditorViewController.h"
@interface NotesListViewController ()
@end
@implementation NotesListViewController
- (NSMutableArray*) notes
{
AppDelegate *appDelegate = (AppDelegate *)[[UIApplication sharedApplication] delegate];
return appDelegate.notes;
}
- (void)viewDidAppear:(BOOL)animated {
// Whenever this view controller appears, reload the table. This allows it to reflect any changes
// made whilst editing notes.
[self.tableView reloadData];
}
- (void)viewDidLoad
{
[super viewDidLoad];
}
#pragma mark - Table view data source
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [self notes].count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *CellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
Note* note = [self notes][indexPath.row];
cell.textLabel.text = note.title;
cell.textLabel.font = [UIFont preferredFontForTextStyle:UIFontTextStyleHeadline];
return cell;
}
#pragma mark - Navigation
// In a story board-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
NoteEditorViewController* editorVC = (NoteEditorViewController*)segue.destinationViewController;
if ([segue.identifier isEqualToString:@"CellSelected"]) {
// if the cell selected segue was fired, edit the selected note
NSIndexPath *path = [self.tableView indexPathForSelectedRow];
editorVC.note = [self notes][path.row];
}
if ([segue.identifier isEqualToString:@"AddNewNote"]) {
// if the add new note segue was fired, create a new note, and edit it
editorVC.note = [Note noteWithText:@" "];
// also, add this note to the collection
[[self notes] addObject:editorVC.note];
}
}
@end