2017-09-16 3 views
0

tableview에서 아래로 스크롤하면 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

Hello @Lamiya, TableView로 작업 할 때 Bundle.main.loadNibNamed를 사용하지 말고 dequeueReusableCellWithIdentifier를 사용하십시오. –

+0

저는 셀을 만들 때마다 이미지를 다시로드하고 어디서나 캐싱하지 않는 것처럼 보이기 때문에 지연이 발생했다고 생각합니다. 얼마나 많은 이미지를 가지고 있느냐에 따라 테이블을 초기화 할 때 일종의 비동기 프로세스를 통해 일부 또는 전부를로드 한 다음 데이터 모델에 저장 한 다음 http를 작성하는 대신 데이터 모델에서로드 할 수 있습니다 : 매번 요청하십시오. – Sparky

답변

0

아래의 두 행은 지연의 근본 원인입니다. 매번 새로운 TableViewCell을 사용하려고합니다. 따라서

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 

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

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

처럼 if and else statementdequeueReusableCellWithIdentifier를 사용해야하고 지금까지이

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

처럼 viewDidLoad()에 펜촉을 등록 깜빡하지 않는이 문제를 해결하기 위해 imageLoading에 관해서는, 나는 당신이 SDWebImage 라이브러리를 사용하고 있다고 생각하기 때문에 스크롤이 지연 될 것이라고 생각하지 않는다. 이미지를 캐시하고 비동기 적으로 작동합니다.

+0

dequeueReusableCellWithIdentifier를 사용하여 반환 없음 셀 – Lamiya

+0

@Lamiya 먼저 'viewDidLoad'에서 펜촉을 등록 했습니까? 안되면 먼저 해주세요 –

+0

그래도 끝냈습니다. 아직 돌아 오지 않습니다 – Lamiya