2016-02-27 24 views
0

我正在用swift爲ios開發應用程序。我卡住了一些東西,我無法從json中正確獲取原始數據。我創建了2個不同的標籤,它應該是獲取json主要類別。它只是重複它自己,而不是由一個人獲取。我也無法獲取圖像。我會將圖像和我的代碼分享給你。謝謝你的幫助。 這裏是我的如何從JSON如何將JSON數據提取到2列中的Prototype Cell

func startParsing(data :NSData) 
    { 
     let dict: NSDictionary!=(try! NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers)) as! NSDictionary 

     for var i = 0 ; i < (dict.valueForKey("PAPATYA") as! NSArray).count ; i++ 
     { 
      arrDict.addObject((dict.valueForKey("PAPATYA") as! NSArray) .objectAtIndex(i)) 
     } 
     for var i = 0 ; i < (dict.valueForKey("BURCU") as! NSArray).count ; i++ 
     { 
      arrDict.addObject((dict.valueForKey("BURCU") as! NSArray) .objectAtIndex(i)) 
     } 
     for var i = 0 ; i < (dict.valueForKey("DENEME") as! NSArray).count ; i++ 
     { 
      arrDict.addObject((dict.valueForKey("DENEME") as! NSArray) .objectAtIndex(i)) 
     } 
     tvJSON .reloadData() 
    } 

解析後,我解析成JSON我會用這個代碼將數據綁定到原型細胞

func tableView(tableView: UITableView, cellForRowAtIndexPath indexPath: NSIndexPath) -> UITableViewCell 
    { 
     let cell : TableViewCell! = tableView.dequeueReusableCellWithIdentifier("Cell") as! TableViewCell 
     let strTitle : NSString=arrDict[indexPath.row] .valueForKey("URUNADI") as! NSString 
     let strfiyat : NSString=arrDict[indexPath.row] .valueForKey("URUNFIYATI") as! NSString 
     cell.product_name.text = strfiyat as String 
     cell.product_price.text = strTitle as String 
     cell.product_name2.text = strTitle as String 
     cell.product_price2.text = strfiyat as String 

     return cell as TableViewCell 
    } 

Simulator Images

這裏是故事板圖片

enter image description here

回答

0

我用uıcollection視圖做到了,這是更好的方法。謝謝