UICollectionView visibleCells returns 0 before scrolling

首页 论坛 iOS UICollectionView visibleCells returns 0 before scrolling

该话题包含 0 个回复,有 1 个参与人,并且由  macRong10 月, 2 周 前 最后一次更新。

正在查看 1 帖子:1-1 (共 1 个帖子)
  • 作者
    帖子
  • #2683

    macRong
    管理员

    在滑动scrollView是取visiblecells

    * thread #1, queue = ‘com.apple.main-thread’, stop reason = breakpoint 1.1
    frame #0: 0x00000001817a84f0 libobjc.A.dylibobjc_exception_throw
    frame #1: 0x000000018255f038 CoreFoundation
    +[NSException raise:format:arguments:] + 104
    frame #2: 0x0000000182ef97f4 Foundation-[NSAssertionHandler handleFailureInMethod:object:file:lineNumber:description:] + 112
    frame #3: 0x000000018bc43248 UIKit
    -[UITableView _configureCellForDisplay:forIndexPath:] + 476
    frame #4: 0x000000018be54ae8 UIKit-[UITableView _createPreparedCellForGlobalRow:withIndexPath:willDisplay:] + 848
    frame #5: 0x000000018be54f94 UIKit
    -[UITableView _createPreparedCellForGlobalRow:willDisplay:] + 80
    frame #6: 0x000000018be33784 UIKit-[UITableView _updateVisibleCellsNow:isRecursive:] + 2188
    frame #7: 0x000000018be3f224 UIKit
    -[UITableView _visibleCellsUsingPresentationValues:] + 428
    * frame #8: 0x00000001009d7f44 MPIns`-[MPFTrackMediaViewManager coveryTableView:](self=0x000000010e51ffa0, _cmd=”coveryTableView:”, sc=0x00000001060c1600) at MPFTrackMediaViewManager.m:229

    🌲解决:
    This is caused by cells being added during layoutSubviews not at reloadData. Since layoutSubviews is performed during next run loop pass after reloadData your cells are empty. Try doing this:

    [self.collectionView reloadData];
    [self.collectionView layoutIfNeeded];
    [self configure cells];

    https://stackoverflow.com/questions/26055626/uicollectionview-visiblecells-returns-0-before-scrolling

    https://stackoverflow.com/questions/18230918/reloading-a-uicollectionview-using-reloaddata-method-returns-immediately-before

正在查看 1 帖子:1-1 (共 1 个帖子)

抱歉,回复话题必需登录。