views:

30

answers:

2

I have a picker that prompts the user to choose a gender and an age group (17-21, 22-26, etc.)

These 2 choices determine which view the user will be brought to after pressing the button, but I am having troubles writing the method for that button. The code I have so far is this:

- (IBAction) buttonPressed {
NSInteger genderRow = [genderPicker selectedRowInComponent:0];
NSString *genderSelected = [genderPickerData objectAtIndex:genderRow];

NSInteger ageRow = [agePicker selectedRowInComponent:1];
NSString *ageSelected = [agePickerData objectAtIndex:ageRow];


if (genderSelected == "Male" && ageSelected == "17-21") {

    Calc2ViewController *calc2ViewController = [[Calc2ViewController alloc] initWithNibName:@"Calc2View" bundle:[NSBundle mainBundle]];

    [self.navigationController pushViewController:calc2ViewController animated:YES];
    [calc2ViewController release];
    calc2ViewController = nil;
}

}

When I run the program, and select these 2 groups (Male and 17-21) - nothing happens. What am I missing?

A: 

If the pickers are separate, single component pickers, is it correct that you are using Component:0 and Component:1 (this would be the case if you had a one picker with two components, but you appear to have two separate pickers).

If this is not the issue, do some debugging: put a break-point at the if line, and figure out what values you do have!

Andiih
+1  A: 
if (genderSelected == "Male" && ageSelected == "17-21")

should be

if ([genderSelected isEqualToString:@"Male"] && [ageSelected isEqualToString:@"17-21"])
Felixyz