Skip to content

Commit

Permalink
fixing dropdown pickers. closes #95
Browse files Browse the repository at this point in the history
  • Loading branch information
Mark Yoon committed Dec 5, 2012
1 parent b794924 commit fb4702a
Show file tree
Hide file tree
Showing 6 changed files with 124 additions and 12 deletions.
27 changes: 26 additions & 1 deletion Frank/features/basic_survey.feature
Expand Up @@ -41,7 +41,32 @@ Feature:
And I press done on the keyboard
And I scroll the table to 676px
Then I should see "NUNoneCell who me (null)"

@focus
Scenario:
Picking from dropdowns
Given I launch the app using iOS 5.1 and the ipad simulator
And the device is in portrait orientation
When I touch the button marked "Inspect"
And I touch the button marked "loadStatesAndDates"
And I wait for .5 seconds
Then I should see "STATE"
When I touch the cell marked "NUPickerCell Pick one"
And I touch "AZ"
And I touch "Done"
Then I should see "NUPickerCell AZ"
And there should be 1 response
When I touch the cell marked "NUPickerCell AZ"
And I touch "AK"
And I touch a "UINavigationButton" marked "Done"
Then I should see "NUPickerCell AK"
And there should be 1 response
When I go to the "Dates" section
And I touch the cell marked "NUPickerCell Pick one"
Then I should see "JANUARY"
When I touch "MARCH"
And I touch a "UINavigationButton" marked "Done"
Then there should be 2 responses

# Somehow, the touch table cell marked "Complicated questions" isn't working in landscape with the split view
# Scenario:
# Scrolling and switching sections, horizontal
Expand Down
3 changes: 3 additions & 0 deletions Frank/features/step_definitions/response_set_steps.rb
Expand Up @@ -57,6 +57,9 @@
check_element_exists("label marked:'#{expected_mark}'")
end

Then /^I touch a "(.*)" marked "(.*)"$/ do |viewClass, mark|
touch("view:'#{viewClass}' marked:'#{mark}'")
end
When /^I use the keyboard to fill in the textfield marked "([^\\"]*)" with "([^\\"]*)"$/ do |text_field_mark, text_to_type|
text_field_selector = "view marked:'#{text_field_mark}'"
check_element_exists( text_field_selector )
Expand Down
4 changes: 4 additions & 0 deletions NUSurveyor.xcodeproj/project.pbxproj
Expand Up @@ -53,6 +53,7 @@
3B8CF201151B91C600EA4148 /* test-birth-date-survey.json in Resources */ = {isa = PBXBuildFile; fileRef = 3B8CF200151B91C600EA4148 /* test-birth-date-survey.json */; };
3BA2E94A14CDCD0F0057D05C /* NUSurvey.h in Headers */ = {isa = PBXBuildFile; fileRef = 3BA2E94814CDCD0F0057D05C /* NUSurvey.h */; };
3BA2E94B14CDCD0F0057D05C /* NUSurvey.m in Sources */ = {isa = PBXBuildFile; fileRef = 3BA2E94914CDCD0F0057D05C /* NUSurvey.m */; };
3BB92966166FE58E00C2D5AE /* states-and-dates.json in Resources */ = {isa = PBXBuildFile; fileRef = 3BB92965166FE58E00C2D5AE /* states-and-dates.json */; };
3BC61A7E1520CBDB00A8C20C /* NUAnyStringOrNumberCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 3BC61A7C1520CBDB00A8C20C /* NUAnyStringOrNumberCell.h */; };
3BC61A7F1520CBDB00A8C20C /* NUAnyStringOrNumberCell.m in Sources */ = {isa = PBXBuildFile; fileRef = 3BC61A7D1520CBDB00A8C20C /* NUAnyStringOrNumberCell.m */; };
3BC61A841520F75000A8C20C /* NUAnyDatePickerCell.h in Headers */ = {isa = PBXBuildFile; fileRef = 3BC61A821520F74F00A8C20C /* NUAnyDatePickerCell.h */; };
Expand Down Expand Up @@ -254,6 +255,7 @@
3B8CF200151B91C600EA4148 /* test-birth-date-survey.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "test-birth-date-survey.json"; sourceTree = "<group>"; };
3BA2E94814CDCD0F0057D05C /* NUSurvey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NUSurvey.h; path = Models/NUSurvey.h; sourceTree = "<group>"; };
3BA2E94914CDCD0F0057D05C /* NUSurvey.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NUSurvey.m; path = Models/NUSurvey.m; sourceTree = "<group>"; };
3BB92965166FE58E00C2D5AE /* states-and-dates.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = "states-and-dates.json"; sourceTree = "<group>"; };
3BC61A7C1520CBDB00A8C20C /* NUAnyStringOrNumberCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NUAnyStringOrNumberCell.h; path = Views/NUAnyStringOrNumberCell.h; sourceTree = "<group>"; };
3BC61A7D1520CBDB00A8C20C /* NUAnyStringOrNumberCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = NUAnyStringOrNumberCell.m; path = Views/NUAnyStringOrNumberCell.m; sourceTree = "<group>"; };
3BC61A821520F74F00A8C20C /* NUAnyDatePickerCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = NUAnyDatePickerCell.h; path = Views/NUAnyDatePickerCell.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -962,6 +964,7 @@
67DB49CF14D094F2009CC8C3 /* kitchen-sink-survey.json */,
3BF970E01524F9DC008D3A9A /* mustache.json */,
3BDB4BD41536123A00868F97 /* pbj.json */,
3BB92965166FE58E00C2D5AE /* states-and-dates.json */,
67DB49AD14D09454009CC8C3 /* NUSurveyorExample-Info.plist */,
67DB49AE14D09454009CC8C3 /* InfoPlist.strings */,
67DB49B114D09454009CC8C3 /* main.m */,
Expand Down Expand Up @@ -1283,6 +1286,7 @@
3BDB4BD51536123A00868F97 /* pbj.json in Resources */,
3B5ACC18162F5203007EED1A /* sesame.json in Resources */,
3B5ACC1A162F521C007EED1A /* hidden.feature in Resources */,
3BB92966166FE58E00C2D5AE /* states-and-dates.json in Resources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
27 changes: 17 additions & 10 deletions NUSurveyor/Views/NUPickerCell.m
Expand Up @@ -37,21 +37,26 @@ - (void)configureForData:(id)dataObject tableView:(UITableView *)tableView index
self.sectionTVC = (NUSectionTVC *)[tableView delegate];
self.textLabel.text = @"Pick one";
self.textLabel.textColor = [UIColor blackColor];
for (int i = 0; i < [self.answers count]; i++) {
if ([[self.sectionTVC responsesForIndexPath:[NSIndexPath indexPathForRow:i inSection:indexPath.section]] lastObject]) {
self.textLabel.text = [[self.answers objectAtIndex:i] valueForKey:@"text"];
self.textLabel.textColor = RGB(1, 113, 233);
}
}

if (self.pickerController == nil) {
self.pickerController = [[NUPickerVC alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self.pickerController];
self.pickerController.contentSizeForViewInPopover = CGSizeMake(384.0, 216.0);
self.popoverController = [[UIPopoverController alloc] initWithContentViewController:nav];
[self.pickerController setupDelegate:self withTitle:@"Pick one" date:NO];
self.popoverController.delegate = self;
}

[self.pickerController setupDelegate:self withTitle:@"Pick one" date:NO];
self.popoverController.delegate = self;
[self.pickerController.picker selectRow:0 inComponent:0 animated:NO];

// look up existing response, fill in text and set picker
for (int i = 0; i < [self.answers count]; i++) {
NSManagedObject *existingResponse = [[self.sectionTVC responsesForIndexPath:[NSIndexPath indexPathForRow:i inSection:indexPath.section]] lastObject];
if (existingResponse) {
self.textLabel.text = [[self.answers objectAtIndex:i] valueForKey:@"text"];
self.textLabel.textColor = RGB(1, 113, 233);
[self.pickerController.picker selectRow:i inComponent:0 animated:NO];
}
}
}
- (void)selectedinTableView:(UITableView *)tableView indexPath:(NSIndexPath *)indexPath{
[self.popoverController presentPopoverFromRect:self.frame inView:tableView permittedArrowDirections:UIPopoverArrowDirectionAny animated:NO];
Expand All @@ -64,7 +69,9 @@ - (void) pickerDone{
[self.popoverController dismissPopoverAnimated:NO];
NSUInteger selectedRow = [self.pickerController.picker selectedRowInComponent:0];
if (selectedRow != -1) {
[self.sectionTVC deleteResponseForIndexPath:[self myIndexPathWithRow:selectedRow]];
for (int i = 0; i < [self.answers count]; i++) {
[self.sectionTVC deleteResponseForIndexPath:[self myIndexPathWithRow:i]];
}
[self.sectionTVC newResponseForIndexPath:[self myIndexPathWithRow:selectedRow]];
[self.sectionTVC showAndHideDependenciesTriggeredBy:[self myIndexPathWithRow:selectedRow]];
self.textLabel.text = [(NSDictionary *)[self.answers objectAtIndex:selectedRow] objectForKey:@"text"];
Expand Down
14 changes: 13 additions & 1 deletion NUSurveyorExample/NUSpyVC.m
Expand Up @@ -16,10 +16,12 @@ @interface NUSpyVC()
@property (nonatomic, strong) UIButton *pbj;
@property (nonatomic, strong) UIButton *sesame;
@property (nonatomic, strong) UIButton *blankMustache;
@property (nonatomic, strong) UIButton *statesAndDates;
- (void) loadKitchenSink;
- (void) loadComplexResponses;
- (void) loadMustache;
- (void) loadPbj;
- (void) loadStatesAndDates;
@end

@implementation NUSpyVC
Expand All @@ -32,7 +34,8 @@ @implementation NUSpyVC
mustache = _mustache,
pbj = _pbj,
sesame = _sesame,
blankMustache = _blankMustache;
blankMustache = _blankMustache,
statesAndDates = _statesAndDates;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
Expand Down Expand Up @@ -111,6 +114,12 @@ - (void)viewDidLoad
[self.blankMustache addTarget:self action:@selector(loadBlankMustache) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.blankMustache];

self.statesAndDates = [UIButton buttonWithType:UIButtonTypeRoundedRect];
self.statesAndDates.frame = CGRectMake(10, 10.0 + 7*36.0 + 7*10.0, 400.0, 36.0);
self.statesAndDates.accessibilityLabel = @"loadStatesAndDates";
[self.statesAndDates setTitle:@"Load States And Dates" forState:UIControlStateNormal];
[self.statesAndDates addTarget:self action:@selector(loadStatesAndDates) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:self.statesAndDates];
}
- (void) loadKitchenSink{
[self.delegate loadSurvey:@"kitchen-sink-survey"];
Expand All @@ -133,6 +142,9 @@ - (void) loadPbj{
- (void) loadSesame{
[self.delegate loadSurvey:@"sesame"];
}
- (void) loadStatesAndDates {
[self.delegate loadSurvey:@"states-and-dates"];
}

- (void)viewWillAppear:(BOOL)animated {
self.responseSetCount.text = [NSString stringWithFormat:@"%d %@", [self.sectionTVC.responseSet responseCount], ([self.sectionTVC.responseSet responseCount] == 1 ? @"response" : @"responses")];
Expand Down
61 changes: 61 additions & 0 deletions NUSurveyorExample/states-and-dates.json
@@ -0,0 +1,61 @@
{
"sections": [
{
"questions_and_groups": [
{
"answers": [
{
"text": "AL",
"uuid": "41eb3580-2441-4abd-bfb3-21d3d0ad60c6"
},
{
"text": "AK",
"uuid": "45960908-d454-47be-967d-eb8bf5f37ad3"
},
{
"text": "AZ",
"uuid": "a38ec424-1ac9-4cd5-9da5-814d3bd5dd94"
},
{
"text": "AR",
"uuid": "bb507c61-a256-4e81-890d-3014fd0aa9ca"
}

],
"pick": "one",
"text": "STATE",
"type": "dropdown",
"uuid": "84bff7f9-e086-4fd0-b4ef-bd582abf617a"
}
],
"title": "States"
},
{
"questions_and_groups": [
{
"answers": [
{
"text": "JANUARY",
"uuid": "66f56120-9ae4-4902-bad5-02c3bdc7d5fe"
},
{
"text": "FEBRUARY",
"uuid": "adf3aa90-49f1-464b-b7ec-ced345374c8c"
},
{
"text": "MARCH",
"uuid": "307803a1-4bc6-4ec8-aa23-ec7d4eccc5c0"
}
],
"pick": "one",
"text": "MONTH:",
"type": "dropdown",
"uuid": "a409f3e5-1514-46f0-9880-58863f76069b"
}
],
"title": "Dates"
}
],
"title": "States and Dates",
"uuid": "d91e5bfd-1567-4d18-b844-18a43cd20122"
}

0 comments on commit fb4702a

Please sign in to comment.