Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/112.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone UIPickerView出现,但不显示数据_Iphone_Ios_Nsmutablearray_Uipickerview - Fatal编程技术网

Iphone UIPickerView出现,但不显示数据

Iphone UIPickerView出现,但不显示数据,iphone,ios,nsmutablearray,uipickerview,Iphone,Ios,Nsmutablearray,Uipickerview,在过去的两天里,我一直在到处寻找答案,但我似乎找不到答案。据我所知,我的一切都设置正确,但它只是不想工作 我的应用程序扫描QRCode标签并将其保存到可变数组中。我需要创建一种方法,以便用户可以从数组中删除一些标记对象,因此我使用UIPickerView显示标记编号列表,从中选择要删除的标记 以下是我所拥有的: 在.h文件中 @interface ViewController : UIViewController UIPickerView *tagPickerView; NSMu

在过去的两天里,我一直在到处寻找答案,但我似乎找不到答案。据我所知,我的一切都设置正确,但它只是不想工作

我的应用程序扫描QRCode标签并将其保存到可变数组中。我需要创建一种方法,以便用户可以从数组中删除一些标记对象,因此我使用UIPickerView显示标记编号列表,从中选择要删除的标记

以下是我所拥有的:

在.h文件中

@interface ViewController : UIViewController
    UIPickerView *tagPickerView;
    NSMutableArray *tagPickerData;

@property (nonatomic, retain) IBOutlet UIPickerView *tagPickerView;
@property (nonatomic, retain) NSMutableArray *tagPickerData;
在.m文件中

    @synthesize tagPickerView;
    @synthesize tagPickerData;

-(void) viewDidLoad{
        tagPickerData = [[NSMutableArray alloc]init];
        [tagPickerView setDelegate:self];
        [tagPickerView setDataSource:self];
    }

- (void) dealloc{
    [tagPickerView release];
    [tagPickerData release];
    [super dealloc];
}

- (void) imagePickerController: (UIImagePickerController*) reader
     didFinishPickingMediaWithInfo: (NSDictionary*) info
    {
    [tagPickerData addObject:tagString]; //tagString is the value returned from the QRCode reader
}

  #pragma mark -
#pragma mark tagPickerView Data Source Methods
-(NSInteger)numberOfComponentsInPickerView:(UIPickerView *)tagPickerView{
    return 1;
}

-(NSInteger)pickerView:(UIPickerView *)tagPickerView
numberOfRowsInComponent:(NSInteger)component{
    return [tagPickerData count];


}

#pragma mark tagPickerView Delegate Methods
-(NSString *)pickerView:(UIPickerView *)tagPickerView
            titleForRow:(NSInteger)row
           forComponent:(NSInteger)component{
    return [self.tagPickerData objectAtIndex:row];
}
我想这就是一切

在IB中,我为文件的所有者设置了dataSource、delegate和tagPickerView。UIPickerView一直隐藏,直到在本例中调用delete命令,晃动手机,然后它出现在所有内容的顶部

我得到的是一个空白的选择器视图

我可以使用NSLog验证每次执行扫描时是否填充了阵列,因此我知道不是加载了空阵列。我还可以验证数据源方法是否被读取,因为我可以将组件的数量更改为2,并且当选择器出现时会反映出来-两个旋转的轮子。但我不知道如何验证委托方法是否有效

我想知道是否有一种方法可以在命令上填充选择器,比如当手机摇晃时,而不是使用代理。。。或者它会那样工作吗

所有参考资料的问题在于,它演示了如何使用用对象初始化的数组,即

NSArray *array = [[NSArray alloc] initWithObjects:@"String 1",@"string 2",@string 3",(etc.) ,nil];
但我似乎找不到任何显示如何从用户收集的信息创建的数组加载选择器的内容。常识告诉我,它应该以同样的方式工作,但我已经学会在使用Objective-C时放弃常识

有没有UIPickerView专家可以帮我


谢谢

无论何时更改tagPickerData数组的内容,都需要调用[tagPickerView reloadAllComponents]。选择器对其底层数据一无所知,您必须向其发送该消息,让其知道应该调用其数据源方法。

完美!这正是我所需要的,我想这比我想象的更直观。我回顾了我看到的所有示例,没有一个提到使用reloadAllComponents消息。非常感谢!