-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPSRMasterViewController.m
More file actions
81 lines (61 loc) · 2.45 KB
/
PSRMasterViewController.m
File metadata and controls
81 lines (61 loc) · 2.45 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
//
// PSRMasterViewController.m
// SimpleNotes
//
// Created by Daniil Korotin on 24.04.14.
// Copyright (c) 2014 Daniil Korotin. All rights reserved.
//
#import "PSRMasterViewController.h"
#import "PSRNoteManager.h"
#import "PSRDetailViewController.h"
@interface PSRMasterViewController ()
@end
@implementation PSRMasterViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
self.tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain];
self.tableView.dataSource = self;
self.tableView.delegate = self;
[self.view addSubview:self.tableView];
self.navigationItem.title = @"Notes";
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(addNote)];
self.navigationItem.rightBarButtonItem = addButton;
}
- (void)addNote {
PSRNote *note = [[PSRNote alloc] init];
[[PSRNoteManager sharedManager] addOrUpdateNote:note];
[self.tableView reloadData];
}
- (void)viewWillAppear:(BOOL)animated {
[self.tableView reloadData];
}
#pragma mark - UITableView delegate methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [[[PSRNoteManager sharedManager] notes] count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
static NSString *cellIdentifier = @"Cell";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
}
PSRNote *note = [[[PSRNoteManager sharedManager] notes] objectAtIndex:indexPath.row];
cell.textLabel.text = note.text;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
PSRDetailViewController *detailVC = [[PSRDetailViewController alloc] init];
PSRNote *note = [[[PSRNoteManager sharedManager] notes] objectAtIndex:indexPath.row];
// detailVC.textView.text = note.text;
detailVC.note = note;
[self.navigationController pushViewController:detailVC animated:YES];
}
@end