首页 \ 问答 \ 挑选者里面的黑色(Black inside the pickerview)

挑选者里面的黑色(Black inside the pickerview)

它在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;
}

It is all black in the UIPickerView. I do not know what is happening. I do not have warnings and errors and when I try to bring up the picker view it just shows black. Did I do something wrong and is there a possibility that I have forgoten something.

This is my code.

@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];
}

Update

- (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];

}

In my .h file i have

#define genre 0



@interface CameraSave : UIViewController <UIPickerViewDataSource,UIPickerViewDelegate,UIImagePickerControllerDelegate> {


    BOOL FrontCamera;
    BOOL haveImage;

    IBOutlet UIPickerView     *SaveTopicker;
    NSMutableArray            *arraygenre;
}

原文:https://stackoverflow.com/questions/18223083
更新时间:2022-05-11 21:05

最满意答案

你分配和初始化pickerview ?? 是代表设置?

在viewDidLoad中尝试这个

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

有关更多参考,请参阅本教程1教程2


have you allocate & intialize pickerview?? and is delegate is set?

try this in viewDidLoad

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

for more reference check this Tutorial1, Tutorial 2

相关问答

更多

相关文章

更多

最新问答

更多
  • 如何重新加载下拉列表(How to reload dropdownlist)
  • RStudio:在脚本中保留特殊字符(RStudio: keeping special characters in a script)
  • Powershell的“GetLatest”不会在新的TFS工作区上下载文件(“GetLatest” with Powershell doesn't download files on new TFS workspace)
  • 我如何让JS识别一个由字符组成的数组?(How do I get JS to recognise an array insted of characters?)
  • EF从存储过程中急切加载(EF eager loading from stored procedure)
  • 将输出文件添加到Python扩展(Adding output file to Python extension)
  • 淮北职业技术学院电脑应用专业咋样?
  • 更改默认扩展面板箭头的箭头样式(Change arrow style for default expansion panel arrow)
  • 芜湖计算机(计算机)培训机构(培训班,学校)哪家好
  • 致命错误:使用clang-llvm ASTMatcher时未找到'stddef.h'文件(fatal error: 'stddef.h' file not found when using clang-llvm ASTMatcher)
  • 内容的.NET缓存(Contentful .NET caching)
  • 客户端没有发生WCF回调(WCF callback is not happening in client)
  • 使用friend在全局范围内调用类成员函数会产生27个错误(Calling a Class member function in Global Scope using friend Gives 27 ERRORS)
  • 如何绑定到WPF中的另一个控件属性(How to Bind to Another Control Property in WPF)
  • 南华大学电脑专业,就业好不好
  • 是否存在泄密文件的官方(或常见)文件扩展名或后缀?(Is there an official (or common) file extention or suffix for deflated files?)
  • 在SVM python中只训练一次(Training only once in SVM python)
  • 淘汰自定义绑定光滑js无法正常工作(knockout custom binding for slick js not working)
  • 似乎无法正确地抓住网站“福布斯”(Can't seem to scrape the website “Forbes” properly)
  • 无法使用boto.rds2从describe_instance方法检索有关db实例的信息(Not able to retrieve information about db instances from the describe_instance method using boto.rds2)
  • 转换为英国日期格式问题(Convert to british date format issue)
  • 在表中列出不同的元组(10种方法)(List distinct tuples in a table(SQL query)(10 ways))
  • OrientDB查询比较(OrientDB query compare)
  • 全局变量有什么不好?(What is so bad about global variables? [duplicate])
  • 为什么JavaMail Transport.send()是一个静态方法?(Why is JavaMail Transport.send() a static method?)
  • 获取最近3个Instagram图像张贴在一个地方(Get last 3 instagram images posted in a place)
  • 使用libnfc格式化/读/写NDEF Mifare 1K卡(Format/Read/Write NDEF Mifare 1K Card using libnfc)
  • 阻止谷歌索引特定图像(Block Google from indexing a particular image)
  • 消息模板接收让Dispatcher没有订阅频道(Message Template receive gives Dispatcher has no subscribers for channel)
  • OpenShift:使用自定义节点版本(OpenShift: Use custom node version)