1

我是 Xcode 的新手。我正在尝试在一个视图中构建两个 UIPickerView。第一个 UIPickerView 中的数据如期而至,但我无法在第二个 UIPickerView 中获取数据。一个选择器有一个组件,另一个有两个组件。

- (NSInteger)numberOfComponentsInPickerView:
(UIPickerView *)pickerView
{ 
if (pickerView == showData) 
    return 1;
else 
    return 2;

}


- (NSInteger)pickerView:(UIPickerView *)pickerView
numberOfRowsInComponent:(NSInteger)component
{
if (pickerView == showData)

switch (tapButton) {

    case 1:
        return [countryData count];
        break;
    case 2:
        return [serviceData count];
        break;
    case 3:
        return [budgetData count];
        break;
    default:
        return 0;
  }
 else {
    if (component == 0)
        return [hourTime count];
else 
    return [minuteTime count];
}
}

- (NSString *)pickerView:(UIPickerView *)pickerView
         titleForRow:(NSInteger)row
        forComponent:(NSInteger)component
{
if (pickerView == showData)
switch(tapButton)
{
case 1:
    return [countryData objectAtIndex:row];
    break;
case 2:
    return [serviceData objectAtIndex:row];
    break;
case 3:
    return [budgetData objectAtIndex:row];
    break;
default:
    return @"nothing";
 }

  else {
    if (component == 0)
        return [hourTime objectAtIndex:row];
    else 
        return [minuteTime objectAtIndex:row];
 }



} 
4

1 回答 1

1
           - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:
           (NSInteger)component        
        {
            if(component ==0)
            {
                return [serviceArray count];
            }
            else {
                if ([Service isEqualToString:@"Hair"]) {
                    return [HairServices count];
                }
                if ([Service isEqualToString:@"Beauty"]) {
                    return [BeautyServices count];
                }
                if ([Service isEqualToString:@"Make Up"])
                {
                    return [MakeUpServices count];
                }
                if ([Service isEqualToString:@"Eye lash extensions"])
                {
                    return [EyelashServices count];
                }

                else  {
                    return [HairServices count];
                }
            }

            return 0;

           }

        - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row 

        {

             [DisplayArray addObjectsFromArray:HairServices];
            if(component ==0)
            {
                return  [serviceArray objectAtIndex:row];
            }
            else {
                if ([Service isEqualToString:@"Hair"]) {
                   // NSLog(@"DIS %@",DisplayArray);
                    [DisplayArray removeAllObjects];
                    [DisplayArray addObjectsFromArray:HairServices];
                   // NSLog(@" DISPLAY %@", DisplayArray);

                    return [DisplayArray objectAtIndex:row];
                }
                if ([Service isEqualToString:@"Beauty"]) {
                    [DisplayArray removeAllObjects];
                    [DisplayArray addObjectsFromArray:BeautyServices];

                    return [DisplayArray objectAtIndex:row];        }
                if ([Service isEqualToString:@"Make Up"])
                {
                    [DisplayArray removeAllObjects];
                    [DisplayArray addObjectsFromArray:MakeUpServices];

                    return [DisplayArray objectAtIndex:row];
                }
                if ([Service isEqualToString:@"Eye lash extensions"])
                {
                    [DisplayArray removeAllObjects];
                    [DisplayArray addObjectsFromArray:EyelashServices];

                    return [DisplayArray objectAtIndex:row];
                }

                else  {
                    return [HairServices objectAtIndex:row];
                }
            }

           return 0;

           }
        - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row 
          inComponent:(NSInteger)component
        {
            if (component == 0) {
                Service=[[NSString alloc] initWithFormat:@"%@" , [serviceArray 
                  objectAtIndex:row]];
                [servicelistPicker reloadComponent:1];
            }



            else
            {
                NSLog(@" dis  %@",DisplayArray);
                if([DisplayArray count]>0)
                {
                    SelectedServices =[NSString stringWithFormat:@"%@,",[DisplayArray  




                    NSLog(@"%@",DisplayArray);
                    //[TempString appendString:SelectedServices];
                    ServicesTxt.text = SelectedServices;
                    ServicesTxt.font = [UIFont boldSystemFontOfSize:13];
                }

            }
        }
于 2013-05-23T07:01:13.750 回答