iphone UIPicker问题

时间:2010-06-13 18:13:34

标签: iphone objective-c

我有一个选择器,提示用户选择性别和年龄组(17-21,22-26等)

这两个选项确定按下按钮后用户将被带到哪个视图,但是我在编写该按钮的方法时遇到了麻烦。我到目前为止的代码是:

- (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;
}

}

当我运行程序时,选择这两组(男性和17-21) - 没有任何反应。我错过了什么?

2 个答案:

答案 0 :(得分:1)

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

应该是

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

答案 1 :(得分:0)

如果选择器是单独的,单个组件选择器,你使用Component:0和Component:1是正确的(如果你有一个带有两个组件的选择器就是这种情况,但你似乎有两个独立的拾取器)。

如果这不是问题,请做一些调试:在if行放一个断点,找出你有的值!