1

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;
}
4

2 回答 2

0

你有分配和初始化pickerview吗?并且代表设置了吗?

在 viewDidLoad 中试试这个

SaveTopicker.delegate = self;
SaveTopicker.showsSelectionIndicator = YES;
[self.view addSubview:SaveTopicker];

如需更多参考,请查看本教程1 、教程 2

于 2013-08-14T05:02:51.393 回答
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;
}

根据您的需要尝试此代码...希望此 wprks 适合您..

于 2013-08-14T05:11:35.620 回答