2017-09-16 5 views
0

テーブルビューをスクロールダウンすると、TextViewの読み込み速度が遅くなり、スクロールが途切れます。遅れて遅いTextViewロード

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

     if arrayofCellData[indexPath.row].isDesc == false{ 
      let cell = Bundle.main.loadNibNamed("imagesTableViewCell", owner: self, options: nil)?.first as! imagesTableViewCell 
      let indexA = self.arrayofCellData[indexPath.row].text 
      let path = "http://a"+indexA! 
      let url = URL(string: path) 
      cell.detailsImg.sd_setImage(with: url) 
      return cell 

     } 
      else { 
      let cell = Bundle.main.loadNibNamed("imagesTableViewCellDesc", owner: self, options: nil)?.first as! imagesTableViewCellDesc 

      let textD = self.arrayofCellData[indexPath.row].text! 
      let style = NSMutableParagraphStyle() 
      style.lineSpacing = 12 
      let attributes = [NSParagraphStyleAttributeName : style] 
      cell.descText.attributedText = NSAttributedString(string: textD, attributes:attributes) 
         cell.descText.textColor = UIColor.white 
         cell.descText.font = UIFont(name: (cell.descText.font?.fontName)!, size: 16) 
         cell.descText.textAlignment = .right 


      return cell 
     } 
    } 
+0

'sd_setImage'はどのように定義されていますか? –

+0

こんにちは@Lamiya、TableViewで作業しているときにBundle.main.loadNibNamedを使用しないでください。この1つをdequeueReusableCellWithIdentifierとしてください。 –

+0

私はいつもあなたがセルを構築し、どこにでもそれらをキャッシュしていないときにイメージを再読み込みしているように見えるので、遅延が起こっていると思います。あなたが持っている画像の数に応じて、テーブルが初期化されたときに何らかの非同期処理を介してそれらの一部または全部をロードしてからデータモデルに保存し、httpを作成するのではなくそこからロードすることができます:毎回リクエストしてください。 – Sparky

答えて

0

以下の2行が、あなたの遅れの原因です。毎回新しいTableViewCellを使用しようとしています。あなたは

let cell = tableView.dequeueReusableCellWithIdentifier("imagesTableViewCell", forIndexPath: indexPath) as imagesTableViewCell 

let cell = tableView.dequeueReusableCellWithIdentifier("imagesTableViewCellDesc", forIndexPath: indexPath) as imagesTableViewCellDesc 

と限りこの

tableView.register(UINib(nibName: "imagesTableViewCellDesc", bundle: nil), forCellReuseIdentifier: "imagesTableViewCellDesc") 
tableView.register(UINib(nibName: "imagesTableViewCell", bundle: nil), forCellReuseIdentifier:"imagesTableViewCell") 

ようviewDidLoad()であなたのペン先を登録するのを忘れないでください、以下のようなあなたのif and else statementdequeueReusableCellWithIdentifierを使用する必要があり、これを解決するために

したがって
let cell = Bundle.main.loadNibNamed("imagesTableViewCell", owner: self, options: nil)?.first as! imagesTableViewCell 

let cell = Bundle.main.loadNibNamed("imagesTableViewCellDesc", owner: self, options: nil)?.first as! imagesTableViewCellDesc 

imageLoadingについては、私はあなたがSDWebImageライブラリを使用していると思うので、スクロールするのが遅くなるとは思わないイメージをキャッシュし、非同期で動作します。

+0

dequeueReusableCellWithIdentifierを使用して戻り値なしセル – Lamiya

+0

@Lamiya最初にあなたのペン先を 'viewDidLoad'に登録してもらえますか?していない場合は、まずそれをしてください –

+0

私はやったが、それでもnilを返す – Lamiya

関連する問題