[Swift4] TableView의 특정 줄만 다시 불러오는 reloadRows 방법에 대해 조사를 진행했습니다.

4558 단어 SwiftiOS

방법

let indexPath = IndexPath(row: 1, section: 0)
tableView.reloadRows(at: [indexPath], with: .fade)
reloadRows(at:with:) - UITableView | Apple Developer Documentation

해설


첫 번째 매개변수at:[indexPath]


다시 불러올 줄을 지정합니다.
NSIndexPath 객체는 여러 줄을 지정할 수 있습니다.
let indexPath_1 = IndexPath(row: 1, section: 0)
let indexPath_2 = IndexPath(row: 2, section: 0)
tableView.reloadRows(at: [indexPath_1, indexPath_2], with: .fade)
NSIndexPath - Foundation | Apple Developer Documentation

두 번째 매개변수 with:.fade


다시 불러올 때 애니메이션하는 방식을 지정합니다.
애니메이션은 TableView 클래스에서 다음과 같이 정의되는 몇 가지 유형이 있습니다.
public enum RowAnimation : Int {

    case fade

    case right // slide in from right (or out to right)

    case left

    case top

    case bottom

    case none // available in iOS 3.0

    case middle // available in iOS 3.2.  attempts to keep cell centered in the space it will/did occupy

    case automatic // available in iOS 5.0.  chooses an appropriate animation style for you
}
차이를 보기 위해 reload 버튼을 누르면 TableView 위에 다섯 줄이 다시 불러오는 샘플을 만듭니다.

.fade


자주 보는 무거운 짐인 것 같아서요.

.right


왼쪽에서 오른쪽으로 무거운 짐을 싣다.

.bottom


위에서 아래로 무거운 짐이 필요하다.

생각보다 확연히 다르고 재미있지만 평소 사용해도 나무랄 데가 없다.애니메이션이 없습니다.주변에 많은 것 같아요.
UITableView.RowAnimation - UITableView | Apple Developer Documentation

좋은 웹페이지 즐겨찾기