Prens
Prens

Reputation: 420

How to connect UIPickerView datasource and delegate in storyboard

I have created a new project in Ios5 using storyboards and my project has a UIPickerView.

I created a datasource and delegate and I cannot find the files owner to make connections in IOs5 . What should I make the connections to?

Upvotes: 0

Views: 2651

Answers (2)

user1316896
user1316896

Reputation:

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

Upvotes: 0

Caleb
Caleb

Reputation: 124997

One difference between storyboards and loading .xib files is that the view controller for each "scene" in a storyboard file is included in that file. So, assuming that your view controller is also the data source and delegate for your picker (this is common), connect the view controller to those outlets instead of the file's owner proxy. (With .xib files, it's typical to instantiate the view controller in code and give it a .xib file from which to load its view, so the view controller is the file's owner.)

Upvotes: 2

Related Questions