如何在故事板中连接UIPickerView数据源和委托

时间:2012-05-09 20:24:40

标签: iphone ios uipickerview

我使用故事板在Ios5中创建了一个新项目,我的项目有一个UIPickerView。

我创建了一个数据源和委托,我找不到文件所有者在IOs5中建立连接。我该怎么连接?

2 个答案:

答案 0 :(得分:2)

故事板和加载.xib文件之间的一个区别是故事板文件中每个“场景”的视图控制器都包含在该文件中。因此,假设您的视图控制器也是选择器的数据源和委托(这很常见),请将视图控制器连接到那些插座而不是文件的所有者代理。 (对于.xib文件,通常在代码中实例化视图控制器并为其提供一个.xib文件,从中加载其视图,因此视图控制器是文件的所有者。)

答案 1 :(得分:0)

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