在tableview中向上滚动时,UITableViewCell为空

时间:2017-09-14 10:12:12

标签: ios swift3

  • 我不滚动tableView时的第一张图片

我的子项目是显示

MY SubItems are Show

  • 第二张图片滚动tableView时

我的子项目是空白的

 MY SubItems are blank

我的CellFor行代码是

func createDashedLine(thisPoint: CLLocationCoordinate2D, nextPoint: CLLocationCoordinate2D, color: UIColor) {
    let difLat = nextPoint.latitude - thisPoint.latitude
    let difLng = nextPoint.longitude - thisPoint.longitude
    let scale = camera.zoom * 2
    let divLat = difLat / scale
    let divLng = difLng / scale
    let tmpOrig = thisPoint

    var singleLinePath = GMSMutablePath()

    for i in 0 ..< scale {
        var tmpOri = tmpOrig
        if i > 0 {
            tmpOri = CLLocationCoordinate2DMake(tmpOrig.latitude + (divLat * 0.25), tmpOrig.longitude + (divLng * 0.25))
        }

        singleLinePath.addCoordinate(tmpOri)
        singleLinePath.addCoordinate(CLLocationCoordinate2DMake(tmpOrig.latitude + (divLat * 1.0), tmpOrig.longitude + (divLng * 1.0)))
        tmpOri = CLLocationCoordinate2DMake(tmpOrig.latitude + (divLat * 1.0), tmpOrig.longitude + (divLng * 1.0))
    }

    let polyline = GMSPolyline(path: singleLinePath)
    polyline.geodesic = false
    polyline.strokeWidth = 5.0
    polyline.strokeColor = color
    polyline.map = mapView

    //Setup line style and draw

    lengths = [(singleLinePath.lengthOfKind(kGMSLengthGeodesic) / 100)]
    polys = [polyline]
    setupStyle(with: color)
    tick()
}

func tick() {
    for poly in polys {
        poly.spans = GMSStyleSpans(poly.path, styles, lengths, kGMSLengthGeodesic, pos)
    }

    pos -= step
}

func setupStyle(with color: UIColor) {
    let gradColor = GMSStrokeStyle.gradient(from: color, to: color)
    styles = [gradColor, GMSStrokeStyle.solidColor(.white)]
    step = 50000
}

1 个答案:

答案 0 :(得分:0)

尽量避免在行的单元格中使用for循环,在构建数据源时,可以创建这些选项名称并将其存储在带有某个键的数组中,然后每次在cellforrow中重用该键,而不是再次创建n试。

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
相关问题