2017-04-07 55 views
0

我有4個按鈕(日期1,日期2,時間1和時間2)和3個標籤的按鈕,我可以分配從給定的輸出的標籤用作分配數據從服務目標C

_lblName.text = [medicationdicts objectForKey:@"Name"]; 
_lblMedicine.text = [medicationdicts objectForKey:@"Medicine"]; 
_lblDate.text = [medicationdicts objectForKey:@"ExpDate"]; 

但是,如何能我從以下輸出中爲按鈕指定日期和時間(Date1 = 2017-04-05,Date2 = 2017-04-06,Time1 = 07:00:00和Time2 = 07:10:00)

Name = Abhi; 
Medicine = Colpol; 
Time =  (
        { 
         Date = "2017-04-05"; 
         Time = "07:00:00"; 
        }, 
        { 
         Date = "2017-04-06"; 
         Time = "07:10:00"; 
        } 
        ); 
ExpDate = "2017-04-30"; 

幫我解決這個問題。 TIA

回答

0

你可以做這樣的...

NSArray *times = [medicationdicts objectForKey:@"Time"]; 

    for (NSDictionary *timeDict in times) 
    { 
     NSString *time = [timeDict objectForKey:@"Date"]; 
     NSString *date = [timeDict objectForKey:@"Time"]; 

     if ([times indexOfObject:timeDict] == 0) 
     { 
      [dateButton1 setTitle: date forState: UIControlStateNormal]; 
      [timeButton1 setTitle: time forState: UIControlStateNormal]; 
     } 
     else 
     { 
      [dateButton2 setTitle: date forState: UIControlStateNormal]; 
      [timeButton2 setTitle: time forState: UIControlStateNormal]; 
     } 
    } 
+0

感謝@raki工作就像一個天才 – Rajeev

+0

標記答案接受,這將可幫助他人。@拉傑夫 – raki

0

您可以設置標題是這樣的:

[dateButton setTitle: @"date" forState: UIControlStateNormal]; 

來獲得日期

medicationdicts[@"Time"][@"Date"]; 

我建議你解析JSON到您創建e.g Medication和使用medication.title的典範。

編輯:objectForKey:工作正常。