我在网上看了又看,没有找到太多关于这个的!
我想知道您如何将图像放入 UIPicker 中,以便每一行都有不同的图像。
#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
@synthesize pickerContent;
@synthesize p1;
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
//////////
- (NSMutableArray *)pickerContent
{
if(!pickerContent) {
pickerContent = [[NSMutableArray alloc] initWithObjects:
[UIImage imageNamed:@"one.jpg"],
[UIImage imageNamed:@"two.jpg"],
[UIImage imageNamed:@"three.jpg"],
[UIImage imageNamed:@"four.jpg"],
[UIImage imageNamed:@"five.jpg"], nil];
}
return pickerContent;
}
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
if ([pickerView isEqual:p1])
{
return 4;
}
return 0;
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component
{
if ([pickerView isEqual:p1])
{
if (component == R1)return [self.pickerContent count];
if (component == R2)return [self.pickerContent count];
if (component == R3)return [self.pickerContent count];
if (component == R4)return [self.pickerContent count];
}
return 0;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
if ([pickerView isEqual:p1])
{
if (component== R1)return [pickerContent objectAtIndex:row];
if (component== R2)return [pickerContent objectAtIndex:row];
if (component== R3)return [pickerContent objectAtIndex:row];
if (component== R4)return [pickerContent objectAtIndex:row];
}
return 0;
}
@end