2017-06-19 20 views
0

我有一个选择服务中的单选按钮的问题。我有3个单选按钮的问题。在问题1中,我有3个单选按钮(John,Mike,David),并且插座连接到g​​roupButtons(_hasNameRadioButton)。以下是服务Radiobutton应根据服务数据选择Objective-C(重新发布)

{ 
    "DataTable": [ 
        { 
         "EmpNames": { 
          "empName": "David", 
          "empid": "243", 
          "empEdu": "B.Tech" 

         } 
        } 
        ] 
} 

我该如何设置单选按钮给大卫。

这是我试过的。但不能有任何想法如何做

#pragma mark - MRConnection Delegate Methods 

- (void)jsonData:(NSDictionary *)jsonDict 
{ 
    [SVProgressHUD dismiss]; 

    NSMutableArray *jsonArr; 
    jsonArr=[jsonDict objectForKey:@"DataTable"]; 
    if (![jsonArr isEqual:[NSNull null]]) { 

     if ([[jsonArr objectAtIndex:0] objectForKey:@"EmpNames"]) { 
      NSMutableDictionary *userDict=[[jsonArr objectAtIndex:0] objectForKey:@"EmpNames"]; 

      _txtempId.text=[userDict objectForKey:@"empid"]; 
      _txtempEdu.text=[userDict objectForKey:@"empEdu"]; 
      groupButtons 


      NSMutableString *str = [NSMutableString stringWithFormat:@"%@",[userDict objectForKey:@"empName"]]; 

      if ([str isEqualToString:@"John"]) { 
       [_hasNameRadioButton setSelected:YES]; 
      } 
      else if ([str isEqualToString:@"Mike"]) { 
       [_hasNameRadioButton setSelected:YES]; 
      } 
      else if ([str isEqualToString:@"David"]) { 
       [_hasNameRadioButton setSelected:YES]; 
      } 
     } 
    } 
} 
+0

这是什么意思“在问题1我有3个单选按钮(约翰·麦克,大卫)和出口连接到groupButtons(_hasNameRadioButton)。下面是服务“? 什么是groupButtons?在连接插座的位置添加代码。 –

+0

这是什么hasNameRadioButton? – vaibby

回答

0
if ([jsonArr isKindOfClass:[NSArray class]]) { 
for (int i = 0; i < jsonArr.count; i++) { 
       if ([[jsonArr objectAtIndex:i] objectForKey:@"EmpNames"]) { 
     NSMutableDictionary *userDict=[[jsonArr objectAtIndex:i] objectForKey:@"EmpNames"]; 

     _txtempId.text=[userDict objectForKey:@"empid"]; 
     _txtempEdu.text=[userDict objectForKey:@"empEdu"]; 
     groupButtons 


     NSMutableString *str = [NSMutableString stringWithFormat:@"%@",[userDict objectForKey:@"empName"]]; 

     if ([str isEqualToString:@"John"]) { 
      [_hasNameRadioButton setSelected:YES]; 
     } 
     else if ([str isEqualToString:@"Mike"]) { 
      [_hasNameRadioButton setSelected:YES]; 
     } 
     else if ([str isEqualToString:@"David"]) { 
      [_hasNameRadioButton setSelected:YES]; 
     } 
    } 
      }} 
+1

这三个条件的用法是什么if([str isEqualToString:@“John”]){_hasNameRadioButton setSelected:YES]; } else if([str isEqualToString:@“Mike”]){ [_hasNameRadioButton setSelected:YES]; } else if([str isEqualToString:@“David”]){_IsNameRadioButton setSelected:YES]; }无论您设置为setSelected:YES –

+0

您在显示数据或显示选定数据时遇到问题?我的这段代码显示了所有的数据 – vaibby