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;
}
答案 0 :(得分:0)
你有分配&amp;初选pickerview ??代表是否已设置?
在viewDidLoad
中尝试此操作SaveTopicker.delegate = self;
SaveTopicker.showsSelectionIndicator = YES;
[self.view addSubview:SaveTopicker];
有关详情,请查看此Tutorial1,Tutorial 2
答案 1 :(得分:0)
- (void)viewDidLoad
{
[super viewDidLoad];
array=[[NSMutableArray alloc]initWithObjects:@"Reading",@"Music",@"Cricket",@"Movie",@"Travelling",nil];
[hobbyPicker selectRow:1 inComponent:0 animated:NO];
}
-(void)buttonHobby:(id)sender
{
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationDelay:1.0];
[UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
hobbyPicker.frame = CGRectMake(0, 244, 320, 216);
pickerToolbar.frame = CGRectMake(0,200, 320, 44);
[UIView commitAnimations];
}
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
NSUInteger numRows = 5;
return numRows;
}
// tell the picker how many components it will have
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView
{
return 1;
}
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component
{
return [array objectAtIndex:row];
}
// tell the picker the width of each row for a given component
- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)componen
{
CGFloat componentWidth = 0.0;
componentWidth = 135.0;
return componentWidth;
}
根据您的需要尝试此代码...希望这适用于您..