-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayerDetailsViewController.m
86 lines (63 loc) · 1.88 KB
/
PlayerDetailsViewController.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
#import "PlayerDetailsViewController.h"
#import "Player.h"
#import "GamePickerViewController.h"
#define groupCellCount 2
#define textFieldTag 100
@implementation PlayerDetailsViewController
{
NSString* game;
}
@synthesize delegate;
@synthesize nameTextField;
@synthesize detailLabel;
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
game = @"Chess";
self.detailLabel.text = game;
}
- (void)viewDidUnload
{
[self setNameTextField:nil];
[self setDetailLabel:nil];
[super viewDidUnload];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if ([segue.identifier isEqualToString:@"PickGame"])
{
GamePickerViewController *gamePickerViewController =
segue.destinationViewController;
gamePickerViewController.delegate = self;
gamePickerViewController.game = game;
}
}
- (IBAction)cancel:(id)sender
{
[self.delegate playerDetailsViewControllerDidCancel:self];
}
- (IBAction)save:(id)sender
{
Player *player = [[Player alloc] init];
player.game = game;
player.rating = 1;
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:indexPath.row inSection:indexPath.section] ;
UITableViewCell *cell = [self.tableView cellForRowAtIndexPath:indexPath];
UITextField *textField = (UITextField*)[cell viewWithTag:textFieldTag];
player.name = textField.text;
[self.delegate playerDetailsViewController:self didAddPlayer:player];
}
#pragma mark - GamePickerViewControllerDelegate
- (void)gamePickerViewController:(GamePickerViewController *)controller didSelectGame:(NSString *)theGame
{
game = theGame;
self.detailLabel.text = game;
[self.tableView reloadData];
[self.navigationController popViewControllerAnimated:YES];
}
@end