0

picker1を変更すると、picker2がリロードされるはずでしたが、スクロールしたときにのみ発生します。私に何ができる?ありがとう!

    @implementation ViewController

    @synthesize picker1, array1, arrayApple, arraySamsung, picker2, array2;

    - (void)viewDidLoad
    {
        [super viewDidLoad];

        array1 = [[NSMutableArray alloc] initWithObjects:@"Apple", @"Samsung",nil];
        arrayApple = [[NSMutableArray alloc] initWithObjects: @"iPhone 5", @"iPad", @"iPod Touch", @"MacBook Pro", nil];
        arraySamsung = [[NSMutableArray alloc] initWithObjects: @"Galaxy Tab", @"Galaxy S3", @"Galaxy S", @"Galaxy 5", nil];

        self.array2 = self.arrayApple;

        [picker1 reloadAllComponents];
        [picker2 reloadAllComponents];

        // Do any additional setup after loading the view, typically from a nib.
    }

    - (void)viewDidUnload
    {
        [super viewDidUnload];
        // Release any retained subviews of the main view.
    }



    //Picker View Methods

    - (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
        //NSLog(@"Selected Index: %@. Index of selected color: %i", [array1 objectAtIndex:row], row);

        if(pickerView == self.picker1) {
            if(row == 1) {
                [self.array2 removeAllObjects];
                self.array2 = self.arraySamsung;
                [picker2 reloadAllComponents];
                NSLog(@"%@", picker2);
            }
        }


    }


    - (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView{
        return 1;
    }
    - (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {



        if (pickerView == self.picker1) {
            return [array1 count];
        } else {
            return [array2 count];
        }

        return 0;
    }

    - (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {

        if (pickerView == self.picker1) {
            return [self.array1 objectAtIndex:row];
        } else {
            return [self.array2 objectAtIndex:row];
        }

    }



    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
    {
        return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
    }
4

1 に答える 1

0

これを試して

if(row == 1) {
    self.array2 = self.arraySamsung;
} else {
    self.array2 = self.arrayApple;
}
    [picker2 reloadAllComponents];
    NSLog(@"%@", picker2);
于 2012-09-21T17:23:59.737 に答える