2017-09-14 5 views
2
  • 最初のイメージ私は

MYサブアイテムがのUITableViewCellは空であるとき、テーブルビューのスクロール逆さま

MY SubItems are Show

  • 第二の画像とき、私は表示されているのtableViewをスクロールしていないときスクロールテーブルビュー

MYサブアイテムがマイCellFor行のコードは、データソースを構築しながら、行のために細胞内ループのために避けるようにしてください

var aryDictData = [[String:AnyObject]]() 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 

     var aryOptionName = [String]() 
     var strOptionName = String() 

     var cell = DeliveryTableViewCell() 
     cell = tableView.dequeueReusableCell(withIdentifier: "DeliveryTableViewCell") as! DeliveryTableViewCell 
     cell.selectionStyle = .none 

     let productPrice = userDefault.object(forKey: ProductDesConstantNames.KAryStorePrices) as! [String] 

     if indexPath.section == 0{ 
      if indexPath.row < (aryDictData[0]["storeName"]!).count{ 

       cell.lblItemName.text = ((aryDictData[0]["storeName"]! as AnyObject)[indexPath.row] as! String) 

       cell.lblPrice.text = "$\(String(((Double(productPrice[indexPath.row])! + grandTotalProductPrice[indexPath.row]) * Double(numQuntity))))" 

       cell.lblItemQuantity.text = "\(numQuntity)x" 
       cell.lblItemQuantity.textColor = UIColor.init(red: 41/255, green: 144/255, blue: 85/255, alpha: 1.0) 

       let data = aryPreviewOrder[indexPath.row] as! [[String:AnyObject]] 
       print(data) 

       for i in 0..<((aryDictData[0]["options"]! as AnyObject)[indexPath.row]! as AnyObject).count { 
        let optionName = ((((aryDictData[0]["options"]! as AnyObject)[indexPath.row]! as AnyObject)[i] as AnyObject)["option_name"] as! String) 
        let prices = ((((aryDictData[0]["options"]! as AnyObject)[indexPath.row]! as AnyObject)[i] as AnyObject)["price"] as! String) 

        aryOptionName.append("\(optionName) ($\(prices))") 
        //     aryOptionPrices.append("($\(prices))") 

        strOptionName = aryOptionName.joined(separator: "\n") 
        //     strOptionPrice = aryOptionPrices.joined(separator: "\n") 
       } 
       cell.lblOptionNames.text = strOptionName 
       }    
      } 
    } 
    return cell 
} 
+2

あなたがstrOptionName'毎回 '内のデータを取得していることを確認している私は、迅速な3 – KavyaKavita

+0

あなたcellforrowにコードを追加してください?、cell.lblOptionNames.text = strOptionName後cell.layoutIfNeededを()、書き込みその行の前に – Prototype

+0

に取り組んでいます –

答えて

0

で、あなたはこれらを作成することができます

 MY SubItems are blank

空白ですいくつかのキーを持つ配列に格納してから、再びnをもう一度作成する代わりに、そのキーをcellforrowで毎回再利用します。

for i in 0..<((aryDictData[0]["options"]! as AnyObject)[indexPath.row]! as AnyObject).count { 
    let optionName = ((((aryDictData[0]["options"]! as AnyObject) 
    [indexPath.row]! as AnyObject)[i] as AnyObject)["option_name"] as! 
    String) 
    let prices = ((((aryDictData[0]["options"]! as AnyObject) 
    [indexPath.row]! as AnyObject)[i] as AnyObject)["price"] as! String) 
    aryOptionName.append("\(optionName) ($\(prices))") 
    } 
    strOptionName = aryOptionName.joined(separator: "\n") 

    cell.lblOptionNames.text = strOptionName 
+0

私はそれを試しましたが、動作しません – Prototype

関連する問題