-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTableViewController.m
More file actions
83 lines (65 loc) · 2.64 KB
/
TableViewController.m
File metadata and controls
83 lines (65 loc) · 2.64 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
83
//
// TableViewController.m
// Root Beer Tracker
//
// Created by Ryan Holstad on 6/12/15.
// Copyright (c) 2015 Ryan Holstad. All rights reserved.
//
#import "TableViewController.h"
#import "RootBeer.h"
#import "<Parse/Parse.h>"
#import "Collection.h"
@interface TableViewController ()
@property NSMutableArray *openCellIndexPaths;
@property BOOL isRefreshingCollection;
@end
@implementation TableViewController
@synthesize names,collectionTableView;
- (void)viewDidLoad {
[super viewDidLoad];
PFObject *testObject = [PFObject objectWithClassName:@"RootBeer"];
testObject[@"name"] = @"bar";
[testObject saveInBackground];
self.tableView.contentInset = UIEdgeInsetsMake(44,0,0,0);
//self.collectionTableView.backgroundColor = [UIColor colorWithRed:0.93 green:0.97 blue:0.95 alpha:1.0];
self.openCellIndexPaths = [NSMutableArray array];
Collection *collection = [[Collection alloc]init];
for (int i = 0; i<4; ++i) {
[collection.rootBeers addObject:[RootBeer random].name];
}
names = collection.rootBeers;
//[self refreshRoster];
//self.collectionTableView.tableFooterView = [self footerView];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return [names count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
static NSString *simpleTableIdentifier = @"SimpleTableItem";
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:simpleTableIdentifier];
if (cell == nil) {
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:simpleTableIdentifier];
}
cell.textLabel.text = [names objectAtIndex:indexPath.row];
return cell;
}
- (void)fetchedRootBeers:(NSArray*)objects error:(NSError*)error
{
NSArray *sortDescriptors = @[[NSSortDescriptor sortDescriptorWithKey:@"name"
ascending:YES],
[NSSortDescriptor sortDescriptorWithKey:@"rating"
ascending:YES],
[NSSortDescriptor sortDescriptorWithKey:@"purchaseDate"
ascending:YES]];
self.names = [objects sortedArrayUsingDescriptors:sortDescriptors];
self.openCellIndexPaths = [NSMutableArray array];
[self.collectionTableView reloadData];
}
- (void)refreshRoster
{
if (self.isRefreshingCollection) return; //patience young grasshoper.
self.isRefreshingCollection = YES;
}
@end