-
Notifications
You must be signed in to change notification settings - Fork 0
/
DLMainViewController.m
108 lines (86 loc) · 2.85 KB
/
DLMainViewController.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
//
// DLMainViewController.m
// NamesAndFaces
//
// Created by DetroitLabsUser on 3/14/14.
// Copyright (c) 2014 EliotWilliams. All rights reserved.
//
#import "DLMainViewController.h"
#import "DLDetailViewController.h"
#import "Faces.h"
#import "DLFaceCell.h"
#import "DLFaces.h"
@interface DLMainViewController ()
@property (nonatomic, weak) IBOutlet UITableView *facesTableView;
@property (nonatomic, strong) NSArray *facesArray;
@property (nonatomic, strong) DLFaces *face;
@end
@implementation DLMainViewController
#pragma mark - Table View Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
return [_facesArray count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
if (tableView == _facesTableView) {
static NSString *CellIdentifier = @"iCell";
DLFaceCell *iCell = (DLFaceCell *)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
if (iCell == nil) {
iCell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
}
Faces *currentFace = [_facesArray objectAtIndex:[indexPath row]];
iCell.faceNameLabel.text = [currentFace faceName];
iCell.faceImageView.image = [UIImage imageNamed:[currentFace faceImage]];
if ([iCell.hideNameSwitch isOn]) {
iCell.faceNameLabel.hidden = NO;
} else {
iCell.faceNameLabel.hidden = YES;
}
return iCell;
}
return nil;
}
#pragma mark - System Methods
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
_face = [[DLFaces alloc] init];
NSMutableArray *facesList = [_face getAllEntities];
if ([facesList count] > 0) {
[self populateFromContext];
} else {
[self populateFromPList];
}
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
#pragma mark - Business Logic
- (void)populateFromContext
{
}
- (void)populateFromPList
{
NSString *plistFacesListPath = [[NSBundle mainBundle] pathForResource:@"facesList" ofType:@"plist"];
NSArray *plistFacesListArray = [[NSArray alloc] initWithContentsOfFile:plistFacesListPath];
for (NSDictionary *person in plistFacesListArray) {
Faces *thisFace = (Faces *)[_face createEntity];
thisFace.faceImage = person[@"faceImage"];
thisFace.faceName = person[@"faceName"];
thisFace.memorized = person[@"memorized"];
}
_facesArray = [_face getAllEntities];
NSLog(@"%i",(int)[_facesArray count]);
}
@end