Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | |||
5 | 6 | 7 | 8 | 9 | 10 | 11 |
12 | 13 | 14 | 15 | 16 | 17 | 18 |
19 | 20 | 21 | 22 | 23 | 24 | 25 |
26 | 27 | 28 | 29 | 30 | 31 |
Tags
- uiscrollview
- 리펙터링
- 리팩토링
- UITextView
- 클린 코드
- MVVM
- map
- Xcode
- rxswift
- swiftUI
- swift documentation
- ribs
- combine
- Clean Code
- RxCocoa
- Observable
- Protocol
- UICollectionView
- SWIFT
- Human interface guide
- 스위프트
- ios
- clean architecture
- uitableview
- tableView
- 리펙토링
- Refactoring
- 애니메이션
- collectionview
- HIG
Archives
- Today
- Total
김종권의 iOS 앱 개발 알아가기
[iOS - swift] NSNotFound로 안전하게 IndexPath 접근하는 방법 (# scrollToRow, #IndexPath) 본문
iOS 응용 (swift)
[iOS - swift] NSNotFound로 안전하게 IndexPath 접근하는 방법 (# scrollToRow, #IndexPath)
jake-kim 2024. 2. 14. 01:47scrollToRow
- UIScrollView에서 제공하는 scrollToRow(at:at:animated:)라는 메소드를 활용하여 scrollToTop, scrollToBottom과 같은 것을아래처럼 호출이 가능
tableView.scrollToRow(at: .init(row: 0, section: 0), at: .top, animated: true)
- 하지만 scrollToTop을 위해 위처럼 작성할 경우 IndexPath의 row값이 없는 경우 크래시가 발생
// terminating due to uncaught exception of type NSException
tableView.scrollToRow(at: .init(row: 0, section: 0), at: .top, animated: true)
NSNotFound 파라미터 사용
- scrollToRow(at:at:animated:) 애플 문서에 NSNotFound를 row에 넣으면 크래시가 없이 안전한 스크롤 구현이 가능
- 구현
tableView.scrollToRow(at: .init(row: NSNotFound, section: 0), at: .top, animated: true)
* 전체 코드: https://github.com/JK0369/ExNSNotFound
* 참고
- https://developer.apple.com/documentation/uikit/uitableview/1614997-scrolltorow
'iOS 응용 (swift)' 카테고리의 다른 글
[iOS - swift] CALayer 성능 향상 방법 (shouldRasterize, rasterizeationScale, draw) (0) | 2024.02.16 |
---|---|
[iOS - swift] 프로퍼티 assign 개념 (#reference type, #ARC) (0) | 2024.02.15 |
[iOS - swift] Debounce 직접 구현해보기 (0) | 2024.02.13 |
[iOS - swift] DispatchQueue에서 [weak self]를 안써도 되는 이유 이해하기 (0) | 2024.02.10 |
[iOS - swift] 스크롤 끝나는 타이밍 확인 방법 (#UIScrollView, #decelerate, scrollViewDidEndDragging) (0) | 2024.02.09 |
Comments