我在 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 工作并在标签中显示所选项目。有人可以帮我吗?谢谢你