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

 

Swift UITableView 마지막 행으로 이동

안녕하세요. 개발자 드리머즈입니다. Swift에서 UITableView를 다루다보면 scroll을 마지막으로 이동하고 싶을 때가 있습니다.(scroll to bottom) 저의는 UITableView가 section과 row를 다 보여주고나서 마지막..

dreamaz.tistory.com

 

 

 

스크롤뷰

extension UIScrollView {
    func scrollToBottom() {
        let offset = CGPoint(
            x: 0,
            y: contentSize.height - bounds.height
        )
        setContentOffset(offset, animated: false)
    }
}
728x90
반응형