-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGameResultViewController.m
executable file
·100 lines (73 loc) · 2.04 KB
/
GameResultViewController.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
//
// GameResultViewController.m
// Matchino
//
// Created by Mudryak on 18.09.13.
// Copyright (c) 2013 Mudryak. All rights reserved.
//
#import "GameResultViewController.h"
#import "GameResult.h"
@interface GameResultViewController ()
@property (weak, nonatomic) IBOutlet UITextView *display;
@property (nonatomic) SEL sortSelector;
@end
@implementation GameResultViewController
- (IBAction)clearHistory {
}
-(void)updateUI
{
NSString *displayText = @"";
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateStyle:NSDateFormatterShortStyle];
[formatter setTimeStyle:NSDateFormatterShortStyle];
for (GameResult *result in [[GameResult allGameResults] sortedArrayUsingSelector:self.sortSelector]) { // sorted
displayText = [displayText stringByAppendingFormat:@"Score: %d (%@, %0d )\n", result.score, [formatter stringFromDate:result.end], result.duration]; // formatted date
}
self.display.text = displayText;
}
#pragma mark - Sorting
@synthesize sortSelector = _sortSelector;
// return default sort selector if none set (by score)
- (SEL)sortSelector
{
if (!_sortSelector) _sortSelector = @selector(compareScoreToGameResult:);
return _sortSelector;
}
// update the UI when changing the sort selector
- (void)setSortSelector:(SEL)sortSelector
{
_sortSelector = sortSelector;
[self updateUI];
}
- (IBAction)sortByDate
{
self.sortSelector = @selector(compareEndDateToGameResult:);
}
- (IBAction)sortByScore
{
self.sortSelector = @selector(compareScoreToGameResult:);
}
- (IBAction)sortByDuration
{
self.sortSelector = @selector(compareDurationToGameResult:);
}
-(void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self updateUI];
}
-(void)setup
{
//initialization that can't wait until viewDidLoad
}
-(void)awakeFromNib
{
[self setup];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
[self setup];
return self;
}
@end