-
Notifications
You must be signed in to change notification settings - Fork 3
[Feat] #22 - Sticky Header 구현 #23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
군데군데 배열의 축약형을 섞어써서 요건 통일하면 좋을거 같아요!
그리고 로직같은 경우는 같이 좀 더 간단하게 생각해보면 좋을거 같네여! 생각보다 변수가 많이 쓰였던거 같아요! 물론 해봐야겠지만요ㅜ
이거 꽤... 난이도가 있었는데 해낸 수빈선배가 최고얌!!
var dateList: [String] = [] | ||
|
||
var firstList: [Any] = [] | ||
var secondList: Array<Any> = [] | ||
var thirdList: Array<Any> = [] | ||
var fourthList: Array<Any> = [] | ||
var fifthList: Array<Any> = [] | ||
var sixthList: Array<Any> = [] | ||
var seventhList: Array<Any> = [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style share 의 코드컨밴션에도 언급이 되어있구 [Any]
가 Array<Any>
의 축약형이니까 전자의 컨밴션으로 진행하면 좋을것 같습니당!
override init(frame: CGRect) { | ||
super.init(frame: frame) | ||
|
||
setUI() | ||
setLayout() | ||
} | ||
|
||
required init?(coder: NSCoder) { | ||
fatalError("init(coder:) has not been implemented") | ||
} | ||
|
||
override func prepareForReuse() { | ||
super.prepareForReuse() | ||
|
||
dateLabel.text = "" | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
커스텀뷰를 Xib 로 만들때는 init(frame:) 와 init?(coder:) 에 모두 코드를 넣어줬거든요! 그런데 오잉 여긴 없네 해서 다시금 찾아보다가 아래 괜찮은 정보가 있어서 남기고 갑니당!
prepareForReuse()
까지..! 굳굳입니다
참고: https://medium.com/@b9d9/required-init-coder-nscoder-에-대해서-b67ddfc628
while indexPath < datalist.count { | ||
if dateList.isEmpty { | ||
dateList.append(datalist[indexPath]["date"] as! String) | ||
indexPath += 1 | ||
} else { | ||
let day: String = datalist[indexPath]["date"] ?? "" | ||
|
||
if !(dateList.contains(day)) { | ||
dateList.append(day) | ||
} | ||
|
||
indexPath += 1 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오호.. 좋은데요???
이렇게 날짜를 저장하면 될거 같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
다행이다......................
/// sticky header을 가능하도록 하는 코드 | ||
collectionViewFlowlayout.sectionHeadersPinToVisibleBounds = true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오호.... 멋져!
while sectionCount < dateList.count { | ||
var index = 0 | ||
while index < datalist.count && !datalist.isEmpty && sectionCount != dateList.count { | ||
|
||
if dateList[sectionCount] == datalist[index]["date"] { | ||
switch sectionCount { | ||
case 0: | ||
firstList.append(datalist[index]) | ||
case 1: | ||
secondList.append(datalist[index]) | ||
case 2: | ||
thirdList.append(datalist[index]) | ||
case 3: | ||
fourthList.append(datalist[index]) | ||
case 4: | ||
fifthList.append(datalist[index]) | ||
case 5: | ||
sixthList.append(datalist[index]) | ||
case 6: | ||
seventhList.append(datalist[index]) | ||
default: | ||
seventhList.append(datalist[index]) | ||
} | ||
|
||
} | ||
index += 1 | ||
} | ||
sectionCount += 1 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
고생해써여! 이중 while 문은 좀 더 좋은 부분으로 바꿀수도있을거 같아여!!같이 고민해보자구여
func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) { | ||
if (scrollView.contentOffset.y + 1) >= (scrollView.contentSize.height - scrollView.frame.size.height) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
오호 저는 scrollViewDidScroll
사용해서 우르르르르 하고 index 가 증가해서 그걸 막는 변수를 만들었는데 이렇게 사용하면 감속할때 한번 호출되면서 contentOffset 이 넘었으면 더미데이터를 추가하니까 좋은것 같아요! 그리고 감속할때니까 contentOffset 을 1 더해서 넘어남은 스크롤 높이보다 넘게 비교를 해줘야하는군여..! 1제거하니까 잘안먹히더라구여 ㅋㅋㅋ
이 결과물은 한번 끝에 닫고 한번 더 스크롤해야 더미가 추가되더라구여!
제가 노션에 공유한거는 스크롤로 끝에 닿기만해도 추가를 해줘서 한번 더 스크롤 하지 않아도 되거든여! 요거는 코드 결과물을 보고 어떤 메서드를 사용할지 이야기해봐요!
사실 하긴 했는데 이게 맞는지 모르겠고 또 실제 서버 데이터 들어오면 많은 부분이 바뀔 수도 있을거같아서.... 실제 적용하면서 이것저것 더 깔꼼하게 수정해보겠습니다..! |
🌴 PR 요약
🌱 작업한 브랜치
🌱 작업한 내용
📌 참고 사항
무한스크롤 페이징되는 것 더미데이터 넣어서 연습해봤슴니다
서버에서 데이터가 어떤 식으로 들어올지는 아직 잘 모르겠어서 일단 저렇게 했습니다..
📸 스크린샷
📮 관련 이슈