2017-10-06 1 views
-1

UITableView을 사용하여 데이터를 표시하고 있습니다.이미지 UITableView를 스크롤 할 때 이미지가 사라짐

내 데이터는 이미지와 텍스트로 구성됩니다. 문제는 내가 이미지가 사라지는 UITableView을 스크롤 할 때입니다.

내 코드는 다음과 UITableView

func numberOfSections(in tableView: UITableView) -> Int { 
    return 1 
} 

func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { 
    return msgs.count 
} 

func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { 
    let cell = tableView.dequeueReusableCell(withIdentifier: "cell", for: indexPath) as! collCell 
    let msg = msgs[indexPath.row] 
    var decodeImgURL = "" 
    cell.lbl1.text = msg.content 

    decodeImgURL = msg.imgurl 

    if decodeImgURL == "none" { 
     cell.img.isHidden = true 
    } else { 

     let dataDecoded : Data = Data(base64Encoded:decodeImgURL,options: .ignoreUnknownCharacters)! 
     let decodedImage = UIImage(data: dataDecoded) 
     cell.img.image = decodedImage 

    } 

    return cell 
} 

func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat { 

    let msg = msgs[indexPath.row] 

    if msg.imgurl == "none" { 
     return 64 
    } else { 
     return 207 
    } 

} 
+0

'lbl1 '에'msg.content'도 사라지고 있습니까? – thedjnivek

+0

이미지가 맨 처음에도 나타 납니까? –

+0

@thedjnivek 아니요 lbl1은 동일하게 유지됩니다 –

답변

0

, 메모리에있는 유일한 세포는 눈에 보이는 세포이다. 표 셀을 화면 밖으로 스크롤하면 메모리에서 제거됩니다. 이렇게하면 테이블 뷰를 더 빠르게 스크롤 할 수 있습니다. 직면 한 문제는 화면에서 표 셀을 스크롤하면 셀과 이미지가 메모리에서 할당 취소된다는 것입니다. 화면 위로 셀을 다시 스크롤하면 메모리에 다시 할당됩니다. 귀하의 문제는 다음 두 가지 문제 중 하나 일 수 있다고 생각합니다.

1) 이미지가 셀에서 재생성 될 때까지 기다려야합니다.

2) 아마도 msgs 어레이에 문제가있을 수 있습니다. 몇 초 후에 이미지가 나타나지 않으면이 줄 바로 뒤에 중단 점을 넣으십시오 : cell.img.image = decodedImage. 화면에서 셀을 스크롤 한 다음 화면으로 다시 이동 한 후 중단 점에 도달하지 않으면 decodeImgURL (이미지의 URL)이 잘못되었다는 것입니다.

+0

'cell.img.image = decodeImage'에 중단 점을 지정했습니다 yaa 아래로 스크롤 할 때 전체 섹션이 호출되지만 설정되어 있지 않습니다 내 이미지 –

관련 문제