繁体   English   中英

iOS:如何在一个数组中的多个字典中分隔键值?

[英]iOS: How to separate key values in multiple dictionary which is in one array?

我有这样的NSDictionary

(
    {
    bp = "158/56";
    dateTime = "05/12/2016 11:51:12 AM";
    doc =         {
        "email_id" = "gkalal64@gmail.com";
        exception = 0;
        gender = Male;
        id = 0;
        "mobile_no" = 8149910113;
        name = Kabadia;
        "profile_id" = 0;
        qualification = MBBS;
        "reg_id" = 100;
        salutation = Mr;
        "wellness_id" = IN8S2D29A2;
    };
    "follow_up" = 14;
    id = 6;
    medicine =         (
        "Injection,Crocin,5,0-1-0,After Meal,2",
        "Powder,churan,10,1-0-0,Before Meal,14",
        no,
        no,
        no,
        no,
        no,
        no,
        no,
        no
    );
    patient =         {
        "email_id" = "bishtrohit1989@gmail.com";
        exception = 0;
        gender = Male;
        id = 0;
        "mobile_no" = 8624088776;
        name = kamlesh;
        "profile_id" = 0;
        qualification = "";
        "reg_id" = 101;
        salutation = Mr;
        "wellness_id" = IND16HRR65;
    };
    weight = 47;
}
)

我想按以下方式显示以上信息: 在此处输入图片说明 但是我不知道该怎么做。 我搜索了此内容,但我没有确切地知道如何执行此操作。

我做了什么:

在以前的View Controller中,我显示了多个处方标题。 单击特定的单元格后,我调用了此视图,并且得到了服务器上方的响应,我想像上面的图像一样显示。

我已经在屏幕上使用了UITableView

我为此采取了1个静态自定义单元格。

但是我不知道该怎么办。

请任何人都可以解决我的问题。 帮助将是可观的。

更新的答案

if (indexPath.row < responseArray.count){

   NSString *docName = @"";
   NSString *contact = @"";
   NSString *wellness_id = @"";
   if ([selectedDict valueForKey:@"doc"] != nil){

        NSDictionary *doctorDict = [selectedDict valueForKey:@"doc"];
        NSString *lDocName = [doctorDict valueForKey:@"name"];
        if(lDocName.length > 0){
            docName = lDocName;
        }

        NSString *qulification = [doctorDict valueForKey:@"qualification"];
        if(qulification.length > 0){
            docName = [NSString stringWithFormat:@"%@ %@", docName, qulification];
        }

        NSString *mobile_no = [doctorDict valueForKey:@"mobile_no"];
        if(mobile_no.length > 0){
            contact = mobile_no;
        }

        NSString *email_id = [doctorDict valueForKey:@"email_id"];
        if(email_id.length > 0){
            contact = [NSString stringWithFormat:@"%@ / %@", contact, email_id];
        }
        NSString *wellness_idTemp = [doctorDict valueForKey:@"wellness_id"];
        if(wellness_idTemp.length > 0){
            wellness_id= [NSString stringWithFormat:@"Wellness_Id : %@", wellness_idTemp];
        }
  }
  cell.docNameLabel.text = docName;
  cell.contact.text = contact;
  cell.wellnessID.text = wellness_id;

   NSString *patientName = @"";
   NSString *patientcontact = @"";
   NSString *patientWellness_id = @"";
   NSString *bloodPressure = [selectedDict valueForKey:@"bp"];
   NSString *weight = [selectedDict valueForKey:@"weight"];

  if ([selectedDict valueForKey:@"patient"] != nil){

        NSDictionary *patientDict = [selectedDict valueForKey:@"patient"];
        NSString *lName = [patientDict valueForKey:@"name"];
        if(lName.length > 0){
            patientName = lName;
        }

        NSString *mobile_no = [patientDict valueForKey:@"mobile_no"];
        if(mobile_no.length > 0){
            patientcontact = mobile_no;
        }

        NSString *email_id = [patientDict valueForKey:@"email_id"];
        if(email_id.length > 0){
            patientcontact = [NSString stringWithFormat:@"%@ / %@", contact, email_id];
        }
        NSString *wellness_idTemp = [patientDict valueForKey:@"wellness_id"];
        if(wellness_idTemp.length > 0){
            patientWellness_id = [NSString stringWithFormat:@"Wellness Id : %@", wellness_idTemp];
        }
   }
    cell.patientNameLabel.text = patientName;
    cell.contact.text = patientcontact;
    cell.wellnessID.text = wellness_id;
    cell.bp.text = bloodPressure;
    cell.weight.text = weight;
}

希望这会有所帮助。

根据您的数据结构,我猜您的数据属于单个对象,因此很显然它不是同一类型对象的集合(数组),因此我建议您仅为整个单个记录创建单个自定义单元格。

在这种情况下,您的TableView将只有一行。

在“自定义”单元格中:将其称为“ PatientDetail”

  • 添加要为每个属性显示的所有标签和控件,并根据需要连接插座。
  • 如果使用的是“自动布局”,则对所有控件赋予相对约束,否则通过计算其内容的高度来动态设置每个控件的框架。

它将如何工作?

正如您所说的特定列表的详细信息屏幕,因此我们将在tableview中显示包含所有详细信息的单行。

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

在下面的代码中

responseDict NSDictionaryresponseDict的第一个对象,因为您的响应是一种数组。

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{

    PatientDetail *cell=[tableView dequeueReusableCellWithIdentifier:@"PatientDetail" forIndexPath:indexPath];

    //Setting
    [cell.lbDateTime setText:[responseDict valueForKey:@"dateTime"]];
    //Doctor name Just
    [cell.lbDoctorName setText:[[responseDict objectForKey:@"doc"]valueForKey:@"name"]];

    //Follow the above steps for all the details



    return cell;
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM