-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSNChoiceListItemViewController.m
132 lines (105 loc) · 3.64 KB
/
SNChoiceListItemViewController.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
//
// SNChoiceListItemViewController.m
// FulcrumAPIDemo
//
// Created by Ben Rigas on 5/31/12.
// Copyright (c) 2012 Spatial Networks. All rights reserved.
//
#import "SNChoiceListItemViewController.h"
@interface SNChoiceListItemViewController ()
@property (nonatomic, retain) UITextField* nameField;
@property (nonatomic, retain) UITextField* valueField;
@end
@implementation SNChoiceListItemViewController
@synthesize delegate = _delegate;
@synthesize nameField = _nameField;
@synthesize valueField = _valueField;
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
_nameField = [[UITextField alloc] initWithFrame:CGRectMake(75, 5, 295, 34)];
_nameField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
_nameField.delegate = self;
_valueField = [[UITextField alloc] initWithFrame:CGRectMake(75, 5, 295, 34)];
_valueField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
_valueField.delegate = self;
self.title = @"New Choice";
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
UIBarButtonItem* saveButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemSave target:self action:@selector(tappedSave:)];
self.navigationItem.rightBarButtonItem = saveButton;
[saveButton release];
UIBarButtonItem* cancelButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(tappedCancel:)];
self.navigationItem.leftBarButtonItem = cancelButton;
[cancelButton release];
[self.nameField becomeFirstResponder];
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
self.nameField = nil;
self.valueField = nil;
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void) tappedSave:(id)sender
{
SNChoiceListItem* item = [[SNChoiceListItem alloc] init];
item.label = self.nameField.text;
item.value = self.valueField.text;
[self.delegate choiceListItemController:self didFinishWithItem:item];
[item release];
}
- (void) tappedCancel:(id)sender
{
[self.delegate choiceListItemController:self didFinishWithItem:nil];
}
#pragma mark -
#pragma mark UITableView
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
return 1;
}
- (NSInteger) tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 2;
}
- (UITableViewCell*) tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:@"cell"];
if (cell == nil)
{
cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"cell"];
}
cell.selectionStyle = UITableViewCellSelectionStyleNone;
switch (indexPath.row) {
case 0:
[cell addSubview:self.nameField];
cell.textLabel.text = @"Label";
break;
case 1:
[cell addSubview:self.valueField];
cell.textLabel.text = @"Value";
break;
default:
break;
}
return cell;
}
#pragma mark -
#pragma mark UITextFieldDelegate
- (void) textFieldDidEndEditing:(UITextField *)textField
{
}
@end