0

下の画像のように、ピッカーをカスタマイズしようとしています。ピッカーに画像を正常に追加しましたが、他のすべてのピッカーには影響しません。参考までに私のコードも載せておきます。

- (void)loadView
{
    picker1 = [[UIPickerView alloc] initWithFrame:CGRectMake(30, 200, 250, 250)];
    picker1.delegate = self;
    picker1.dataSource = self;
    picker1.showsSelectionIndicator = YES;
    
    
    
    picker2 = [[UIPickerView alloc] initWithFrame:CGRectMake(390, 200, 250, 250)];
    picker2.delegate = self;
    picker2.dataSource = self;
    picker2.showsSelectionIndicator = YES;
    
    
    picker3 = [[UIPickerView alloc] initWithFrame:CGRectMake(750, 200, 250, 250)];
    picker3.delegate = self;
    picker3.dataSource = self;
    picker3.showsSelectionIndicator = YES;
   
    self.view = [[UIView alloc] initWithFrame:CGRectZero];
    [self.view addSubview:picker1];
    [self.view addSubview:picker2];
    [self.view addSubview:picker3];
    
    
    UIImage *seven = [UIImage imageNamed:@"seven.png"];
    UIImage *bar = [UIImage imageNamed:@"bar.png"];
    
    
    for(int i=1; i<=4; i++)
    {
        UIImageView *sevenView = [[UIImageView alloc] initWithImage:seven];
        UIImageView *barView = [[UIImageView alloc] initWithImage:bar];
        
        
        NSArray *imageViewArray = [[NSArray alloc] initWithObjects:
                                   sevenView,barView,nil];
        
        NSString *fieldName = [[NSString alloc] initWithFormat:@"column%d",i];
        [self setValue:imageViewArray forKey:fieldName];
    }

}


-(UIView *)pickerView:(UIPickerView *)pickerView
           viewForRow:(NSInteger)row
         forComponent:(NSInteger)component reusingView:(UIView *)view
{
    NSString *arrayName = [[NSString alloc] initWithFormat:@"column%d",component+1];
    NSArray *array = [self valueForKey:arrayName];
    return [array objectAtIndex:row];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview
    // Release anything that's not essential, such as cached data
}


- (void)dealloc {
    
}

#pragma mark UIPickerViewDelegate methods

- (NSString*)pickerView:(UIPickerView*)pv titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
    return [NSString stringWithFormat:@"%d",row];
}

#pragma mark UIPickerViewDataSource methods

- (NSInteger)numberOfComponentsInPickerView:(UIPickerView*)pv
{
    return 4;
}


- (NSInteger)pickerView:(UIPickerView*)pv numberOfRowsInComponent:(NSInteger)component
{
    return 2;
}

@end

ここに画像の説明を入力

4

1 に答える 1

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

    NSArray *array = nil;

    if (pickerView == picker1) {

        array =  [self valueForKey:@"column1"];
    }
    else if (pickerView == picker2) {

        array =  [self valueForKey:@"column2"];
    }
    else if (pickerView == picker3) {

        array = [self valueForKey:@"column3"];
    }

    return [array objectAtIndex:row];
}
于 2012-11-22T04:16:52.503 に答える