[英]iOS: How to separate key values in multiple dictionary which is in one array?
i have NSDictionary
like this: 我有这样的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;
}
)
I want to display above information like following way: 我想按以下方式显示以上信息: But i have no idea about how to do that. 但是我不知道该怎么做。 i searched for this but i didn't get exactly how to do this. 我搜索了此内容,但我没有确切地知道如何执行此操作。
What i did: 我做了什么:
In previous View controller i have displayed multiple prescription title. 在以前的View Controller中,我显示了多个处方标题。 after click on particular cell, i called this view and i got above response from server, which i want to display like above image. 单击特定的单元格后,我调用了此视图,并且得到了服务器上方的响应,我想像上面的图像一样显示。
I have taken UITableView
on screen for this. 我已经在屏幕上使用了UITableView
。
I have taken 1 static custom cell for this. 我为此采取了1个静态自定义单元格。
But i don't know how to do. 但是我不知道该怎么办。
Please anyone can solve my issue. 请任何人都可以解决我的问题。 help will be appreciable. 帮助将是可观的。
Updated Answer 更新的答案
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;
}
Hope this will help. 希望这会有所帮助。
As per your data structure i guess your data is kind of single object so it's clear that its not a collection(array) of same kind of object so i would suggest you to create only single custom cell for this entire single record. 根据您的数据结构,我猜您的数据属于单个对象,因此很显然它不是同一类型对象的集合(数组),因此我建议您仅为整个单个记录创建单个自定义单元格。
In this case your TableView
will have only single row. 在这种情况下,您的TableView
将只有一行。
In the Custom cell: lets call it 'PatientDetail' 在“自定义”单元格中:将其称为“ PatientDetail”
How it will work ? 它将如何工作?
As you said its detail screen of particular list so we will show single row in tableview with all the details in it. 正如您所说的特定列表的详细信息屏幕,因此我们将在tableview中显示包含所有详细信息的单行。
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
return 1;
}
In the follwing code 在下面的代码中
responseDict
the NSDictionary
which is the first object of response as your response is kind of array. responseDict
NSDictionary
是responseDict
的第一个对象,因为您的响应是一种数组。
-(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.