-
Notifications
You must be signed in to change notification settings - Fork 0
/
MasterViewController.m
246 lines (228 loc) · 9.74 KB
/
MasterViewController.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
//
// MasterViewController.m
// Get_Energy
//
// Created by Korovkina on 02.07.13.
// Copyright (c) 2013 Korovkina. All rights reserved.
//
#import "MasterViewController.h"
#import <NSManagedObjectContext+MagicalRecord.h>
@interface MasterViewController ()
//- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath;
@end
@implementation MasterViewController
- (void)awakeFromNib
{
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}
[super awakeFromNib];
}
- (void)viewDidLoad
{
[super viewDidLoad];
self.delegate = self;
// Do any additional setup after loading the view, typically from a nib.
// self.navigationItem.leftBarButtonItem = self.editButtonItem;
//
// UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
// self.navigationItem.rightBarButtonItem = addButton;
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (void)tabBarController:(UITabBarController *)tabBarController didSelectViewController:(UIViewController *)viewController {
}
//- (vo id)insertNewObject:(id)sender
//{
// NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
// NSEntityDescription *entity = [[self.fetchedResultsController fetchRequest] entity];
// NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:[entity name] inManagedObjectContext:context];
//
// // If appropriate, configure the new managed object.
// // Normally you should use accessor methods, but using KVC here avoids the need to add a custom class to the template.
// [newManagedObject setValue:[NSDate date] forKey:@"timeStamp"];
//
// // Save the context.
// NSError *error = nil;
// if (![context save:&error]) {
// // Replace this implementation with code to handle the error appropriately.
// // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
// NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
// abort();
// }
//}
//
//#pragma mark - Table View
//
//- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
//{
// return [[self.fetchedResultsController sections] count];
//}
//
//- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
//{
// id <NSFetchedResultsSectionInfo> sectionInfo = [self.fetchedResultsController sections][section];
// return [sectionInfo numberOfObjects];
//}
//
//- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
//{
// UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
// [self configureCell:cell atIndexPath:indexPath];
// return cell;
//}
//
//- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
//{
// // Return NO if you do not want the specified item to be editable.
// return YES;
//}
//
//- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
//{
// if (editingStyle == UITableViewCellEditingStyleDelete) {
// NSManagedObjectContext *context = [self.fetchedResultsController managedObjectContext];
// [context deleteObject:[self.fetchedResultsController objectAtIndexPath:indexPath]];
//
// NSError *error = nil;
// if (![context save:&error]) {
// // Replace this implementation with code to handle the error appropriately.
// // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
// NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
// abort();
// }
// }
//}
//
//- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
//{
// // The table view should not be re-orderable.
// return NO;
//}
//
//- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
//{
// if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
// NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
// self.detailViewController.detailItem = object;
// }
//}
//
//- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
//{
// if ([[segue identifier] isEqualToString:@"showDetail"]) {
// NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
// NSManagedObject *object = [[self fetchedResultsController] objectAtIndexPath:indexPath];
// [[segue destinationViewController] setDetailItem:object];
// }
//}
//
//#pragma mark - Fetched results controller
//
//- (NSFetchedResultsController *)fetchedResultsController
//{
// if (_fetchedResultsController != nil) {
// return _fetchedResultsController;
// }
//
// NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
// // Edit the entity name as appropriate.
// NSEntityDescription *entity = [NSEntityDescription entityForName:@"Event" inManagedObjectContext:self.managedObjectContext];
// [fetchRequest setEntity:entity];
//
// // Set the batch size to a suitable number.
// [fetchRequest setFetchBatchSize:20];
//
// // Edit the sort key as appropriate.
// NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"timeStamp" ascending:NO];
// NSArray *sortDescriptors = @[sortDescriptor];
//
// [fetchRequest setSortDescriptors:sortDescriptors];
//
// // Edit the section name key path and cache name if appropriate.
// // nil for section name key path means "no sections".
// NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:self.managedObjectContext sectionNameKeyPath:nil cacheName:@"Master"];
// aFetchedResultsController.delegate = self;
// self.fetchedResultsController = aFetchedResultsController;
//
// NSError *error = nil;
// if (![self.fetchedResultsController performFetch:&error]) {
// // Replace this implementation with code to handle the error appropriately.
// // abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
// NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
// abort();
// }
//
// return _fetchedResultsController;
//}
//
//- (void)controllerWillChangeContent:(NSFetchedResultsController *)controller
//{
// [self.tableView beginUpdates];
//}
//
//- (void)controller:(NSFetchedResultsController *)controller didChangeSection:(id <NSFetchedResultsSectionInfo>)sectionInfo
// atIndex:(NSUInteger)sectionIndex forChangeType:(NSFetchedResultsChangeType)type
//{
// switch(type) {
// case NSFetchedResultsChangeInsert:
// [self.tableView insertSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
// break;
//
// case NSFetchedResultsChangeDelete:
// [self.tableView deleteSections:[NSIndexSet indexSetWithIndex:sectionIndex] withRowAnimation:UITableViewRowAnimationFade];
// break;
// }
//}
//
//- (void)controller:(NSFetchedResultsController *)controller didChangeObject:(id)anObject
// atIndexPath:(NSIndexPath *)indexPath forChangeType:(NSFetchedResultsChangeType)type
// newIndexPath:(NSIndexPath *)newIndexPath
//{
// UITableView *tableView = self.tableView;
//
// switch(type) {
// case NSFetchedResultsChangeInsert:
// [tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
// break;
//
// case NSFetchedResultsChangeDelete:
// [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
// break;
//
// case NSFetchedResultsChangeUpdate:
// [self configureCell:[tableView cellForRowAtIndexPath:indexPath] atIndexPath:indexPath];
// break;
//
// case NSFetchedResultsChangeMove:
// [tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
// [tableView insertRowsAtIndexPaths:@[newIndexPath] withRowAnimation:UITableViewRowAnimationFade];
// break;
// }
//}
//
//- (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
//{
// [self.tableView endUpdates];
//}
//
///*
//// Implementing the above methods to update the table view in response to individual changes may have performance implications if a large number of changes are made simultaneously. If this proves to be an issue, you can instead just implement controllerDidChangeContent: which notifies the delegate that all section and object changes have been processed.
//
// - (void)controllerDidChangeContent:(NSFetchedResultsController *)controller
//{
// // In the simplest, most efficient, case, reload the table view.
// [self.tableView reloadData];
//}
// */
//
//- (void)configureCell:(UITableViewCell *)cell atIndexPath:(NSIndexPath *)indexPath
//{
// NSManagedObject *object = [self.fetchedResultsController objectAtIndexPath:indexPath];
// cell.textLabel.text = [[object valueForKey:@"timeStamp"] description];
//}
//
@end