SWIFT/UIKit
[UIKit] 스크롤뷰/테이블뷰 제일 밑으로 이동
늘스토리 주인장
2022. 8. 6. 23:35
728x90
반응형
테이블뷰
데이터 불러오기 -> 테이블에 데이터 추가 -> 테이블뷰 리로드 -> 제일 밑으로 이동
self.chatResult += chatresult
self.chatTableView.reloadData()
self.scrollToBottom()
func scrollToBottom(){
DispatchQueue.main.async {
if self.chatResult.count > 0 {
let ip = IndexPath(row: self.chatResult.count-1, section: 0)
self.chatTableView.scrollToRow(at: ip, at: .bottom, animated: true)
}
}
refreshControl.endRefreshing()
}
꼭 비동기로 진행해줘야함!!!!
https://dreamaz.tistory.com/350
스크롤뷰
extension UIScrollView {
func scrollToBottom() {
let offset = CGPoint(
x: 0,
y: contentSize.height - bounds.height
)
setContentOffset(offset, animated: false)
}
}
728x90
반응형