0

我在 Xcode 4 中工作,我的选择器视图有一些问题。当 UIPickerView 的选定对象等于“European Sights”时,我不想转到其他视图

这是我要运行的操作:

-(IBAction)switchviewMainToQuiz:(id)sender {


    if([arrayPickerView objectAtIndex:1] == @"European Sights"){

        ViewControllerQuiz *quizView = [[ViewControllerQuiz alloc] initWithNibName:nil bundle:nil];

        [self presentModalViewController:quizView animated:YES];

    }
    else{
        lblPickerView.text = @"werkt niet";
    }
}

这是代码的其余部分(pickerview 代码):

- (void)viewDidLoad
{
    [super viewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    //Put strings in the PickerView and show in label what's selected
    arrayPickerView = [[NSMutableArray alloc] init];
    [arrayPickerView addObject:@"European Sights"];
    [arrayPickerView addObject:@"Flags of the world"];
    [arrayPickerView addObject:@"Something2"];
    [arrayPickerView addObject:@"Something3"];
    [arrayPickerView addObject:@"Something4"];

    [pickerView selectRow:1 inComponent:0 animated:NO];
    lblPickerView.text= [arrayPickerView objectAtIndex:[pickerView selectedRowInComponent:0]];


}

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView;
{
    return 1;
}

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    lblPickerView.text=    [arrayPickerView objectAtIndex:row];
}

- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component;
{
    return [arrayPickerView count];
}

- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component;
{
    return [arrayPickerView objectAtIndex:row];


}

UIPickerView 工作并在标签中显示所选项目。有人可以帮我吗?谢谢你

4

3 回答 3

1
objectAtIndex:0     

obj c 使用从零开始的数组

于 2012-10-17T10:36:25.840 回答
1
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    lblPickerView.text=    [arrayPickerView objectAtIndex:row];

    UIButton *sender = [UIButton buttonWithType:UIButtonTypeCustom]; 
    sender.tag = row;
    [self  switchviewMainToQuiz:(id)sender];  // send a dummy button as the action is conformed for an UIButton interception
}
于 2012-10-17T10:47:27.130 回答
0

试试这行代码:

    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
    {
        lblPickerView.text= [arrayPickerView objectAtIndex:row];
        if(lblPickerView.text isEqualToString:@"European Sights"){
            ViewControllerQuiz *quizView = [[ViewControllerQuiz alloc] initWithNibName:nil bundle:nil];
            [自我presentModalViewController:quizView动画:YES];
        }
        别的{
            lblPickerView.text = @"werkt niet";
        }
    }

于 2012-10-17T10:54:22.377 回答