CGXVerticalMenuListContainerView.m 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519
  1. //
  2. // CGXVerticalMenuListContainerView.m
  3. // CGXVerticalMenuView-OC
  4. //
  5. // Created by CGX on 2018/05/01.
  6. // Copyright © 2019 CGX. All rights reserved.
  7. //
  8. #import "CGXVerticalMenuListContainerView.h"
  9. #import <objc/runtime.h>
  10. #import "CGXVerticalMenuListContainerViewController.h"
  11. @interface CGXVerticalMenuListContainerView () <UIScrollViewDelegate, UICollectionViewDelegate, UICollectionViewDataSource>
  12. @property (nonatomic, weak) id<CGXVerticalMenuListContainerViewDataSource> delegate;
  13. @property (nonatomic, assign,readwrite) NSInteger currentIndex;
  14. @property (nonatomic, strong) NSMutableDictionary <NSNumber *, id<CGXVerticalMenuListContainerViewDelegate>> *validListDict;
  15. @property (nonatomic, assign) NSInteger willAppearIndex;
  16. @property (nonatomic, assign) NSInteger willDisappearIndex;
  17. @property (nonatomic, strong) UICollectionView *collectionView;
  18. @property (nonatomic, strong) CGXVerticalMenuListContainerViewController *containerVC;
  19. @property (nonatomic, strong) UICollectionViewFlowLayout *layout;
  20. @end
  21. @implementation CGXVerticalMenuListContainerView
  22. - (instancetype)initWithDelegate:(id<CGXVerticalMenuListContainerViewDataSource>)delegate
  23. {
  24. self = [super initWithFrame:CGRectZero];
  25. if (self) {
  26. _delegate = delegate;
  27. self.backgroundColor = [UIColor whiteColor];
  28. _validListDict = [NSMutableDictionary dictionary];
  29. _willAppearIndex = -1;
  30. _willDisappearIndex = -1;
  31. _initListPercent = 0.01;
  32. self.isHorizontal = NO;
  33. [self initializeViews];
  34. }
  35. return self;
  36. }
  37. - (void)setIsHorizontal:(BOOL)isHorizontal
  38. {
  39. _isHorizontal = isHorizontal;
  40. if (self.isHorizontal) {
  41. self.layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  42. } else{
  43. self.layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  44. }
  45. self.collectionView.collectionViewLayout = self.layout;
  46. [self.collectionView.collectionViewLayout invalidateLayout];
  47. [self.collectionView reloadData];
  48. }
  49. - (void)initializeViews {
  50. _containerVC = [[CGXVerticalMenuListContainerViewController alloc] init];
  51. self.containerVC.view.backgroundColor = [UIColor clearColor];
  52. [self addSubview:self.containerVC.view];
  53. __weak typeof(self) weakSelf = self;
  54. self.containerVC.viewWillAppearBlock = ^{
  55. [weakSelf listWillAppear:weakSelf.currentIndex];
  56. };
  57. self.containerVC.viewDidAppearBlock = ^{
  58. [weakSelf listDidAppear:weakSelf.currentIndex];
  59. };
  60. self.containerVC.viewWillDisappearBlock = ^{
  61. [weakSelf listWillDisappear:weakSelf.currentIndex];
  62. };
  63. self.containerVC.viewDidDisappearBlock = ^{
  64. [weakSelf listDidDisappear:weakSelf.currentIndex];
  65. };
  66. UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
  67. if (self.isHorizontal) {
  68. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  69. } else{
  70. layout.scrollDirection = UICollectionViewScrollDirectionVertical;
  71. }
  72. layout.minimumLineSpacing = 0;
  73. layout.minimumInteritemSpacing = 0;
  74. self.layout = layout;
  75. if (self.delegate &&
  76. [self.delegate respondsToSelector:@selector(scrollViewClassInlistContainerView:)] &&
  77. [[self.delegate scrollViewClassInlistContainerView:self] isKindOfClass:object_getClass([UICollectionView class])]) {
  78. _collectionView = (UICollectionView *)[[[self.delegate scrollViewClassInlistContainerView:self] alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  79. }else {
  80. _collectionView = [[UICollectionView alloc] initWithFrame:CGRectZero collectionViewLayout:layout];
  81. }
  82. self.collectionView.backgroundColor = self.backgroundColor;
  83. self.collectionView.pagingEnabled = YES;
  84. self.collectionView.showsHorizontalScrollIndicator = NO;
  85. self.collectionView.showsVerticalScrollIndicator = NO;
  86. self.collectionView.scrollsToTop = NO;
  87. self.collectionView.bounces = NO;
  88. self.collectionView.dataSource = self;
  89. self.collectionView.delegate = self;
  90. [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass( [UICollectionViewCell class])];
  91. [self.collectionView registerClass:[UICollectionViewCell class] forCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class])];
  92. if (@available(iOS 10.0, *)) {
  93. self.collectionView.prefetchingEnabled = NO;
  94. }
  95. if (@available(iOS 11.0, *)) {
  96. if ([self.collectionView respondsToSelector:@selector(setContentInsetAdjustmentBehavior:)]) {
  97. self.collectionView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
  98. }
  99. }
  100. [self.containerVC.view addSubview:self.collectionView];
  101. // self.collectionView.translatesAutoresizingMaskIntoConstraints = NO;
  102. // [NSLayoutConstraint activateConstraints:@[
  103. // [self.collectionView.topAnchor constraintEqualToAnchor:self.topAnchor],
  104. // [self.collectionView.leadingAnchor constraintEqualToAnchor:self.leadingAnchor],
  105. // [self.collectionView.trailingAnchor constraintEqualToAnchor:self.trailingAnchor],
  106. // [self.collectionView.bottomAnchor constraintEqualToAnchor:self.bottomAnchor]
  107. // ]];
  108. }
  109. - (void)willMoveToSuperview:(UIView *)newSuperview {
  110. [super willMoveToSuperview:newSuperview];
  111. UIResponder *next = newSuperview;
  112. while (next != nil) {
  113. if ([next isKindOfClass:[UIViewController class]]) {
  114. [((UIViewController *)next) addChildViewController:self.containerVC];
  115. break;
  116. }
  117. next = next.nextResponder;
  118. }
  119. }
  120. - (void)layoutSubviews {
  121. [super layoutSubviews];
  122. self.containerVC.view.frame = self.bounds;
  123. self.collectionView.backgroundColor = self.backgroundColor;
  124. if (CGRectEqualToRect(self.collectionView.frame, CGRectZero) || !CGSizeEqualToSize(self.collectionView.bounds.size, self.bounds.size)) {
  125. [self.collectionView.collectionViewLayout invalidateLayout];
  126. [self.collectionView reloadData];
  127. }
  128. if (!CGRectEqualToRect(self.collectionView.frame, self.bounds)) {
  129. self.collectionView.frame = self.bounds;
  130. }
  131. // self.collectionView.frame = self.bounds;
  132. [self scrollSelectedItemAtIndex:self.currentIndex];
  133. [self.collectionView reloadData];
  134. }
  135. - (void)setinitListPercent:(CGFloat)initListPercent {
  136. _initListPercent = initListPercent;
  137. if (initListPercent <= 0 || initListPercent >= 1) {
  138. NSAssert(NO, @"initListPercent值范围为开区间(0,1),即不包括0和1");
  139. }
  140. }
  141. - (void)setBounces:(BOOL)bounces {
  142. _bounces = bounces;
  143. self.collectionView.bounces = bounces;
  144. }
  145. #pragma mark - UICollectionViewDelegate, UICollectionViewDataSource
  146. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
  147. return [self.delegate numberOfListsInlistContainerView:self];
  148. }
  149. - (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
  150. UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:NSStringFromClass([UICollectionViewCell class]) forIndexPath:indexPath];
  151. cell.contentView.backgroundColor = self.backgroundColor;
  152. id<CGXVerticalMenuListContainerViewDelegate> list = _validListDict[@(indexPath.item)];
  153. BOOL canInitList = YES;
  154. if (self.delegate && [self.delegate respondsToSelector:@selector(listContainerView:canInitListAtIndex:)]) {
  155. canInitList = [self.delegate listContainerView:self canInitListAtIndex:indexPath.item];
  156. }
  157. if (canInitList) {
  158. if (list == nil && self.delegate && [self.delegate respondsToSelector:@selector(listContainerView:initListForIndex:)]) {
  159. list = [self.delegate listContainerView:self initListForIndex:indexPath.item];
  160. if (list != nil) {
  161. _validListDict[@(indexPath.item)] = list;
  162. }
  163. }
  164. for (UIView *subview in cell.contentView.subviews) {
  165. [subview removeFromSuperview];
  166. }
  167. if (list != nil) {
  168. [list listView].frame = cell.contentView.bounds;
  169. [cell.contentView addSubview:[list listView]];
  170. }
  171. }
  172. return cell;
  173. }
  174. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout*)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath {
  175. return self.bounds.size;
  176. }
  177. #pragma mark - UIScrollViewDelegate
  178. - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
  179. if (self.delegate && [self.delegate respondsToSelector:@selector(listContainerViewDidScroll:)]) {
  180. [self.delegate listContainerViewDidScroll:scrollView];
  181. }
  182. if (!scrollView.isDragging && !scrollView.isTracking && !scrollView.isDecelerating) {
  183. return;
  184. }
  185. CGFloat ratio = scrollView.contentOffset.y/scrollView.bounds.size.height;
  186. NSInteger maxCount = round(scrollView.contentSize.height/scrollView.bounds.size.height);
  187. if (self.isHorizontal) {
  188. ratio = scrollView.contentOffset.x/scrollView.bounds.size.width;
  189. maxCount = round(scrollView.contentSize.width/scrollView.bounds.size.width);
  190. }
  191. NSInteger leftIndex = floorf(ratio);
  192. leftIndex = MAX(0, MIN(maxCount - 1, leftIndex));
  193. NSInteger rightIndex = leftIndex + 1;
  194. if (ratio < 0 || rightIndex >= maxCount) {
  195. [self listDidAppearOrDisappear:scrollView];
  196. return;
  197. }
  198. CGFloat remainderRatio = ratio - leftIndex;
  199. if (rightIndex == self.currentIndex) {
  200. //当前选中的在右边,用户正在从右边往左边滑动
  201. if (self.validListDict[@(leftIndex)] == nil && remainderRatio < (1 - self.initListPercent)) {
  202. [self initListIfNeededAtIndex:leftIndex];
  203. }else if (self.validListDict[@(leftIndex)] != nil) {
  204. if (self.willAppearIndex == -1) {
  205. self.willAppearIndex = leftIndex;
  206. [self listWillAppear:self.willAppearIndex];
  207. }
  208. }
  209. if (self.willDisappearIndex == -1) {
  210. self.willDisappearIndex = rightIndex;
  211. [self listWillDisappear:self.willDisappearIndex];
  212. }
  213. }else {
  214. //当前选中的在左边,用户正在从左边往右边滑动
  215. if (self.validListDict[@(rightIndex)] == nil && remainderRatio > self.initListPercent) {
  216. [self initListIfNeededAtIndex:rightIndex];
  217. }else if (self.validListDict[@(rightIndex)] != nil) {
  218. if (self.willAppearIndex == -1) {
  219. self.willAppearIndex = rightIndex;
  220. [self listWillAppear:self.willAppearIndex];
  221. }
  222. }
  223. if (self.willDisappearIndex == -1) {
  224. self.willDisappearIndex = leftIndex;
  225. [self listWillDisappear:self.willDisappearIndex];
  226. }
  227. }
  228. [self listDidAppearOrDisappear:scrollView];
  229. }
  230. - (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
  231. //滑动到一半又取消滑动处理
  232. if (self.willDisappearIndex != -1) {
  233. [self listWillAppear:self.willDisappearIndex];
  234. [self listWillDisappear:self.willAppearIndex];
  235. [self listDidAppear:self.willDisappearIndex];
  236. [self listDidDisappear:self.willAppearIndex];
  237. self.willDisappearIndex = -1;
  238. self.willAppearIndex = -1;
  239. }
  240. }
  241. #pragma mark - Private
  242. - (void)initListIfNeededAtIndex:(NSInteger)index {
  243. if (self.delegate && [self.delegate respondsToSelector:@selector(listContainerView:canInitListAtIndex:)]) {
  244. BOOL canInitList = [self.delegate listContainerView:self canInitListAtIndex:index];
  245. if (!canInitList) {
  246. return;
  247. }
  248. }
  249. id<CGXVerticalMenuListContainerViewDelegate> list = _validListDict[@(index)];
  250. if (list != nil) {
  251. //列表已经创建好了
  252. return;
  253. }
  254. list = [self.delegate listContainerView:self initListForIndex:index];
  255. if ([list isKindOfClass:[UIViewController class]]) {
  256. [self.containerVC addChildViewController:(UIViewController *)list];
  257. }
  258. _validListDict[@(index)] = list;
  259. UICollectionViewCell *cell = (UICollectionViewCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
  260. for (UIView *subview in cell.contentView.subviews) {
  261. [subview removeFromSuperview];
  262. }
  263. if (list != nil) {
  264. [list listView].frame = cell.contentView.bounds;
  265. [cell.contentView addSubview:[list listView]];
  266. }
  267. }
  268. - (void)listWillAppear:(NSInteger)index {
  269. if (![self checkIndexValid:index]) {
  270. return;
  271. }
  272. id<CGXVerticalMenuListContainerViewDelegate> list = _validListDict[@(index)];
  273. if (list != nil) {
  274. [self listWillVCAppearAtIndex:index];
  275. }else {
  276. //当前列表未被创建(页面初始化或通过点击触发的listWillAppear)
  277. BOOL canInitList = YES;
  278. if (self.delegate && [self.delegate respondsToSelector:@selector(listContainerView:canInitListAtIndex:)]) {
  279. canInitList = [self.delegate listContainerView:self canInitListAtIndex:index];
  280. }
  281. if (canInitList) {
  282. id<CGXVerticalMenuListContainerViewDelegate> list = _validListDict[@(index)];
  283. if (list == nil) {
  284. list = [self.delegate listContainerView:self initListForIndex:index];
  285. if ([list isKindOfClass:[UIViewController class]]) {
  286. [self.containerVC addChildViewController:(UIViewController *)list];
  287. }
  288. _validListDict[@(index)] = list;
  289. }
  290. UICollectionViewCell *cell = (UICollectionViewCell *)[self.collectionView cellForItemAtIndexPath:[NSIndexPath indexPathForItem:index inSection:0]];
  291. for (UIView *subview in cell.contentView.subviews) {
  292. [subview removeFromSuperview];
  293. }
  294. if (list != nil) {
  295. [list listView].frame = cell.contentView.bounds;
  296. [cell.contentView addSubview:[list listView]];
  297. }
  298. if (list && [list respondsToSelector:@selector(listWillAppearAtIndex:)]) {
  299. [list listWillAppearAtIndex:index];
  300. }
  301. if ([list isKindOfClass:[UIViewController class]]) {
  302. UIViewController *listVC = (UIViewController *)list;
  303. [listVC beginAppearanceTransition:YES animated:NO];
  304. }
  305. }
  306. }
  307. }
  308. - (void)listDidAppear:(NSInteger)index {
  309. if (![self checkIndexValid:index]) {
  310. return;
  311. }
  312. self.currentIndex = index;
  313. id<CGXVerticalMenuListContainerViewDelegate> list = _validListDict[@(index)];
  314. if (list && [list respondsToSelector:@selector(listDidAppearAtIndex:)]) {
  315. [list listDidAppearAtIndex:index];
  316. }
  317. if ([list isKindOfClass:[UIViewController class]]) {
  318. UIViewController *listVC = (UIViewController *)list;
  319. [listVC endAppearanceTransition];
  320. }
  321. }
  322. - (void)listWillDisappear:(NSInteger)index {
  323. if (![self checkIndexValid:index]) {
  324. return;
  325. }
  326. id<CGXVerticalMenuListContainerViewDelegate> list = _validListDict[@(index)];
  327. if (list && [list respondsToSelector:@selector(listWillDisappearAtIndex:)]) {
  328. [list listWillDisappearAtIndex:index];
  329. }
  330. if ([list isKindOfClass:[UIViewController class]]) {
  331. UIViewController *listVC = (UIViewController *)list;
  332. [listVC beginAppearanceTransition:NO animated:NO];
  333. }
  334. }
  335. - (void)listDidDisappear:(NSInteger)index {
  336. if (![self checkIndexValid:index]) {
  337. return;
  338. }
  339. id<CGXVerticalMenuListContainerViewDelegate> list = _validListDict[@(index)];
  340. if (list && [list respondsToSelector:@selector(listDidDisappearAtIndex:)]) {
  341. [list listDidDisappearAtIndex:index];
  342. }
  343. if ([list isKindOfClass:[UIViewController class]]) {
  344. UIViewController *listVC = (UIViewController *)list;
  345. [listVC endAppearanceTransition];
  346. }
  347. }
  348. - (BOOL)checkIndexValid:(NSInteger)index {
  349. NSUInteger count = [self.delegate numberOfListsInlistContainerView:self];
  350. if (count <= 0 || index >= count) {
  351. return NO;
  352. }
  353. return YES;
  354. }
  355. - (void)listDidAppearOrDisappear:(UIScrollView *)scrollView {
  356. CGFloat currentIndexPercent = scrollView.contentOffset.y/scrollView.bounds.size.height;
  357. if (self.isHorizontal) {
  358. currentIndexPercent = scrollView.contentOffset.x/scrollView.bounds.size.width;
  359. }
  360. if (self.willAppearIndex != -1 || self.willDisappearIndex != -1) {
  361. NSInteger disappearIndex = self.willDisappearIndex;
  362. NSInteger appearIndex = self.willAppearIndex;
  363. if (self.willAppearIndex > self.willDisappearIndex) {
  364. //将要出现的列表在右边
  365. if (currentIndexPercent >= self.willAppearIndex) {
  366. self.willDisappearIndex = -1;
  367. self.willAppearIndex = -1;
  368. [self listDidDisappear:disappearIndex];
  369. [self listDidAppear:appearIndex];
  370. }
  371. }else {
  372. //将要出现的列表在左边
  373. if (currentIndexPercent <= self.willAppearIndex) {
  374. self.willDisappearIndex = -1;
  375. self.willAppearIndex = -1;
  376. [self listDidDisappear:disappearIndex];
  377. [self listDidAppear:appearIndex];
  378. }
  379. }
  380. }
  381. }
  382. - (void)listWillVCAppearAtIndex:(NSInteger)index
  383. {
  384. if (![self checkIndexValid:index]) {
  385. return;
  386. }
  387. id<CGXVerticalMenuListContainerViewDelegate> list = _validListDict[@(index)];
  388. if (list && [list respondsToSelector:@selector(listWillAppearAtIndex:)]) {
  389. [list listWillAppearAtIndex:index];
  390. }
  391. if ([list isKindOfClass:[UIViewController class]]) {
  392. UIViewController *listVC = (UIViewController *)list;
  393. [listVC beginAppearanceTransition:YES animated:NO];
  394. }
  395. }
  396. - (UIScrollView *)contentScrollView {
  397. return self.collectionView;
  398. }
  399. - (void)setDefaultSelectedIndex:(NSInteger)index {
  400. self.currentIndex = index;
  401. }
  402. - (void)scrollingFromLeftIndex:(NSInteger)leftIndex toRightIndex:(NSInteger)rightIndex ratio:(CGFloat)ratio selectedIndex:(NSInteger)selectedIndex {
  403. if (rightIndex == selectedIndex) {
  404. //当前选中的在右边,用户正在从右边往左边滑动
  405. if (ratio < (1 - self.initListPercent)) {
  406. [self initListIfNeededAtIndex:leftIndex];
  407. }
  408. if (self.willAppearIndex == -1) {
  409. self.willAppearIndex = leftIndex;
  410. if (self.validListDict[@(leftIndex)] != nil) {
  411. [self listWillAppear:self.willAppearIndex];
  412. }
  413. }
  414. if (self.willDisappearIndex == -1) {
  415. self.willDisappearIndex = rightIndex;
  416. [self listWillDisappear:self.willDisappearIndex];
  417. }
  418. }else {
  419. //当前选中的在左边,用户正在从左边往右边滑动
  420. if (ratio > self.initListPercent) {
  421. [self initListIfNeededAtIndex:rightIndex];
  422. }
  423. if (self.willAppearIndex == -1) {
  424. self.willAppearIndex = rightIndex;
  425. if (_validListDict[@(rightIndex)] != nil) {
  426. [self listWillAppear:self.willAppearIndex];
  427. }
  428. }
  429. if (self.willDisappearIndex == -1) {
  430. self.willDisappearIndex = leftIndex;
  431. [self listWillDisappear:self.willDisappearIndex];
  432. }
  433. }
  434. }
  435. - (void)didClickSelectedItemAtIndex:(NSInteger)index {
  436. if (![self checkIndexValid:index]) {
  437. return;
  438. }
  439. self.willAppearIndex = -1;
  440. self.willDisappearIndex = -1;
  441. if (self.currentIndex != index) {
  442. [self listWillDisappear:self.currentIndex];
  443. [self listDidDisappear:self.currentIndex];
  444. [self listWillAppear:index];
  445. [self listDidAppear:index];
  446. }
  447. }
  448. - (void)scrollSelectedItemAtIndex:(NSInteger)index
  449. {
  450. if (![self checkIndexValid:index]) {
  451. return;
  452. }
  453. [self.collectionView setContentOffset:CGPointMake(0, 0) animated:NO];
  454. if (self.isHorizontal) {
  455. [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredHorizontally animated:NO];
  456. }else{
  457. [self.collectionView scrollToItemAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:UICollectionViewScrollPositionCenteredVertically animated:NO];
  458. }
  459. self.currentIndex = index;
  460. [self.collectionView reloadData];
  461. }
  462. - (void)reloadData {
  463. for (id<CGXVerticalMenuListContainerViewDelegate> list in _validListDict.allValues) {
  464. [[list listView] removeFromSuperview];
  465. if ([list isKindOfClass:[UIViewController class]]) {
  466. [(UIViewController *)list removeFromParentViewController];
  467. }
  468. }
  469. [_validListDict removeAllObjects];
  470. [self.collectionView reloadData];
  471. [self listWillAppear:self.currentIndex];
  472. [self listDidAppear:self.currentIndex];
  473. }
  474. @end