0

我正在使用情节提要在 IOS5 中创建应用程序。我创建了一个UIPickerview,并且选择选项时,我想打开众多UIViewController中的一个。我只想让用户选择他想要使用的视图控制器。如何连接多个视图控制器。

谢谢普雷纳

4

2 回答 2

1

请为您的选择器视图使用以下委托和数据源

- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view {

        if(button_Number == 1)
        {
            UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 280, 30)];

            NSString *nameStr=[arr_countryName objectAtIndex:row];
            // NSString *nameStr=[programNameArr objectForKey:@"programname"];
            label.text = nameStr;
            label.font = [UIFont boldSystemFontOfSize:14.0f];
            label.textAlignment = UITextAlignmentLeft;
            label.backgroundColor = [UIColor clearColor];
            [label autorelease];
            return label;
        }
        if (button_Number == 2)
        {
            UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(0, 0, 280, 30)];

            NSString *nameStr=[arr_currencyCode objectAtIndex:row];
            // NSString *nameStr=[programNameArr objectForKey:@"programname"];
            label.text = nameStr;
            label.font = [UIFont boldSystemFontOfSize:18.0f];
            label.textAlignment = UITextAlignmentLeft;
            label.backgroundColor = [UIColor clearColor];
            [label autorelease];
            return label;
        }
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
        //return (NSString*)[clientListArray objectAtIndex:row];

        if(button_Number == 1)
        {
            return (NSString*)[arr_countryName objectAtIndex:row];
        }
        if (button_Number == 2)
        {
            return (NSString*)[arr_currencyCode objectAtIndex:row];
        }
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
        return 1;
}
-(NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component{

        if(button_Number == 1)
        {
            return [arr_countryName count];
        }
        if (button_Number == 2)
        {
            return [arr_currencyCode count];
        }
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{

        selectedScrollIndex = row;

        // clientNameTxtFld.text = [clientListArray objectAtIndex:row];

        // LBL.text = [clientListArray objectAtIndex:row];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex 
    {
        if(buttonIndex == 0)
        {

        }

        if (buttonIndex == 1 && button_Number == 1)
        {
            countryTxtFld.text = [arr_countryName objectAtIndex:selectedScrollIndex];
            //selected_Client_ID = [clientIDArray objectAtIndex:selectedScrollIndex]; 

            selectedScrollIndex = 0;
        }

        if (buttonIndex == 1 && button_Number == 2)
        {
            currencyTxtFld.text = [arr_currencyCode objectAtIndex:selectedScrollIndex];
            //selected_Client_ID = [clientIDArray objectAtIndex:selectedScrollIndex]; 

            selectedScrollIndex = 0;
        }
}
于 2012-05-11T08:03:21.020 回答
0

为 .h 文件中的所有视图控制器创建实例,并根据tagUIPickerView 中的 row-touch-title 数组的顺序为所有视图控制器设置值。完成后,继承UIPickerViewDelegate并实现所需的委托方法。

- (void)pickerView:(UIPickerView *)pickerView didSelectRow: (NSInteger)row 
 inComponent:(NSInteger)component {
    // Handle the selection    
    switch (row) {
        case 0:
            [self presentModalViewController:viewController1 animated:YES];
            break;
        case 1:
            [self presentModalViewController:viewController2 animated:YES];
            break;
        case 2:
            [self presentModalViewController:viewController3 animated:YES];
            break;
    }
}
于 2012-05-10T18:35:02.877 回答