Ios 当未触摸选择器时,如何从uipickerview在数组中保存默认值

Ios 当未触摸选择器时,如何从uipickerview在数组中保存默认值,ios,uitableview,uipickerview,Ios,Uitableview,Uipickerview,我在一个视图中添加了标签和按钮,以便在标签中键入内容,并单击标签对应的按钮,出现一个表格视图。在该表中,每个tableviewcell中都有pickerviews。pickerview包含从0到5的数字,用于对文本字段中典型的各个方面的操作进行评分。这样,每个视图中都有多个表视图和选择器。我希望将介于0和5之间的选定值保存在数组中。当不接触选择器时,我希望相应的未接触选择器中的默认值保存在数组中 希望你能理解我的需要。请帮我解决这个问题 多谢各位 - (void)pickerView:(UIPi

我在一个视图中添加了
标签
和按钮,以便在
标签
中键入内容,并单击标签对应的
按钮
,出现一个表格视图。在该表中,每个
tableviewcell
中都有
pickerviews
pickerview
包含从0到5的数字,用于对文本字段中典型的各个方面的操作进行评分。这样,每个视图中都有多个
表视图
选择器
。我希望将介于0和5之间的选定值保存在数组中。当不接触选择器时,我希望相应的未接触选择器中的默认值保存在数组中

希望你能理解我的需要。请帮我解决这个问题

多谢各位

- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{

    cln_total+=row;
    self.cln_label_total.text=[NSString stringWithFormat:@"%d",cln_total];
    NSLog(@"cln_total is  %d",cln_total);
    QSCEAppDelegate* qsceObj=(QSCEAppDelegate*)[[UIApplication sharedApplication]delegate];
    NSLog(@"row is %d",row);
    qsceObj.temp=qsceObj.temp+row;
    NSLog(@"temp @ didselectrow is %d",qsceObj.temp);
    [qsceObj.selectednums_second addObject:[NSNumber numberWithInt:row]];
    NSLog(@"qsceObj.selectednums_second %@",qsceObj.selectednums_second);
    NSLog(@"qsceObj.app_city %@",qsceObj.app_city);
    value=row;
    NSLog(@"value in didselectrow in picker is %d",value);
    NSLog(@"qsceObj.picview_sec %@",qsceObj.picView_sec);

 }
我的
功能消失了

   -(void)viewDidDisappear:(BOOL)animated
{ QSCEAppDelegate*myAppdelegate=[[UIApplication sharedApplication]delegate];

   for(i=0;i<=44;i++)
    {
    int r=[myAppdelegate.picView_sec selectedRowInComponent:0];
   NSLog(@"r %d is %d",i,r);
    if([myAppdelegate.picView_sec selectedRowInComponent:0]==-1)
    {
        [myAppdelegate.selectednums_second addObject:[NSNumber numberWithInt:0]];
    }
    else
    {
       [myAppdelegate.selectednums_second addObject:[NSNumber numberWithInt:[myAppdelegate.picView_sec selectedRowInComponent:0]]];
    }
     NSLog(@"myAppdelegate.selectednums_second is%@",myAppdelegate.selectednums_second);
  }
}
-(void)viewdiddefine:(BOOL)动画
{QSCEAppDelegate*myAppdelegate=[[UIApplication sharedApplication]委托];

对于(i=0;i让我告诉您我是如何获得默认值的

@property (strong, nonatomic) NSMutableArray* _jsonDictionary; // this is array to show the values 
在viewDidLoad中,我使用字典初始化数组

for (int row = 0; row < 3; row++) {
    NSArray *keys = @[@"UserId",@"PreferenceId",@"NumericValue",@"StringValue",@"BooleanValue"                     ];
    NSArray *objects = @[@(userId), @(row + 1), @(1),  @"", @0];
    NSLog(@"%@", objects);
    [_jsonDictionary insertObject:[NSDictionary dictionaryWithObjects:objects forKeys:keys] atIndex:row];
}

这对我有用希望这能帮助你

展示你在-(void)pickerView:(UIPickerView*)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)组件好的…我将把它放在这里…-事实上我已经添加了注释以保存pickerview中的值。谢谢您的回复…nyways让我试试…希望它也对我有用…:)I我的ViewDidDemouse函数我已经编写了将所选值从选择器保存到数组的代码…但问题是当我记录数组时…我获得了所有所选值,但默认值0出现在所有所选值之后。我希望默认值以相同的顺序保存,而不是保存在所有所选值之后。有人这样做吗我知道怎么做。谢谢你…你应该在didSelectDelegate上设置值,而不是在VEWDIDDISPEAREAR上,但是当我在didSelectDelegate中设置值时,只有当选择选择器时,才会将该值保存到数组中。如果我错了,请纠正我。k.是的,最初你在数组和当用户更新任何新值时,将更新到数组中,这样就不会出现任何问题
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component {
    NSArray *keys = @[@"UserId",@"PreferenceId",@"NumericValue",@"StringValue",@"BooleanValue"                     ];
    NSArray *objects = nil;
    switch (_pickerSelectedIndex.row) {
        case 0:
            objects = @[@([userInfo.userId intValue]), @(_pickerSelectedIndex.row + 1), @(row + 1), @"", @0];
            if([_jsonDictionary safeObjectAtIndex:0] != nil) {
                [_jsonDictionary removeObjectAtIndex:0];}
            [_jsonDictionary insertObject:[NSDictionary dictionaryWithObjects:objects forKeys:keys] atIndex:0];
            break;
        case 1:
            objects = @[@([userInfo.userId intValue]), @(_pickerSelectedIndex.row + 1), @(row + 1), @"", @0];

            [[NSUserDefaults standardUserDefaults] setObject:[NSNumber numberWithInt:row] forKey:@"GenderPrefrence"];
            if([_jsonDictionary safeObjectAtIndex:1] != nil) {
                [_jsonDictionary removeObjectAtIndex:1]; }
            [_jsonDictionary insertObject:[NSDictionary dictionaryWithObjects:objects forKeys:keys] atIndex:1];
            break;
        case 2:
            objects = @[@([userInfo.userId intValue]), @(_pickerSelectedIndex.row + 1), @(row + 1), @"", @0];
            if([_jsonDictionary safeObjectAtIndex:2] != nil) {
                [_jsonDictionary removeObjectAtIndex:2]; }
            [_jsonDictionary insertObject:[NSDictionary dictionaryWithObjects:objects forKeys:keys] atIndex:2];
            break;
    }
}