UIPickerView 中全是黑色的。我不知道发生了什么。我没有警告和错误,当我尝试调出选择器视图时,它只显示黑色。我是否做错了什么,是否有可能我忘记了什么。
这是我的代码。
@synthesize stillImageOutput, imagePreview, captureImage, cameraSwitch, pickerViewContainer;
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)thePickerView {
return 1;
}
- (NSInteger)pickerView:(UIPickerView *)thePickerView numberOfRowsInComponent:(NSInteger)component {
if (component == genre)
return [arraygenre count];
return 0;
}
- (NSString *)pickerView:(UIPickerView *)thePickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component {
if (component == genre)
return [arraygenre objectAtIndex:row];
return 0;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// Custom initialization
}
return self;
}
- (IBAction)saveButton:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
pickerViewContainer.frame = CGRectMake(0, 307, 320, 261);
[UIView commitAnimations];
}
- (IBAction)closeButton:(id)sender {
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.3];
pickerViewContainer.frame = CGRectMake(0, 800, 320, 261);
[UIView commitAnimations];
}
更新
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
FrontCamera = NO;
cameraSwitch.selectedSegmentIndex = 1;
captureImage.hidden = YES;
arraygenre = [[NSMutableArray alloc] init];
[arraygenre addObject:@"blue"];
[arraygenre addObject:@"yellow"];
[arraygenre addObject:@"white"];
[arraygenre addObject:@"red"];
[arraygenre addObject:@"purple"];
[arraygenre addObject:@"Others"];
pickerViewContainer.frame = CGRectMake(0, 800, 320, 261);
}
- (void)viewDidAppear:(BOOL)animated {
[self initializeCamera];
}
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component{
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
//fetch Category Name from the array used to fill the Picker View
NSString *categoryName= [arraygenre objectAtIndex:row];
NSString *fPath = [documentsDirectory stringByAppendingPathComponent:categoryName];
NSFileManager *fileManager=[[NSFileManager alloc]init];
[fileManager createDirectoryAtPath:fPath withIntermediateDirectories:YES attributes:nil error:nil];
UIImage *image = captureImage.image;
NSData *data = UIImagePNGRepresentation(image);
[data writeToFile:fPath atomically:YES];
}
在我的 .h 文件中,我有
#define genre 0
@interface CameraSave : UIViewController <UIPickerViewDataSource,UIPickerViewDelegate,UIImagePickerControllerDelegate> {
BOOL FrontCamera;
BOOL haveImage;
IBOutlet UIPickerView *SaveTopicker;
NSMutableArray *arraygenre;
}