UICollectionView reloadData Cell 图片闪烁一下 - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
niselover
V2EX    iDev

UICollectionView reloadData Cell 图片闪烁一下

  •  
  •   niselover 2016-10-15 20:54:03 +08:00 11850 次点击
    这是一个创建于 3301 天前的主题,其中的信息可能已经有所发展或是发生改变。
    collectionCell 里包含个 imageView
    刷新时 cell 闪烁一下 咋回事。。
    performBatchUpdates:completion:也闪
    reloadIndexPath:也闪
    reloadSections:也闪
    好急。。
    21 条回复    2016-10-17 12:46:15 +08:00
    kitalphaj
        1
    kitalphaj  
       2016-10-15 20:56:28 +08:00
    刷新当然会闪。。
    niselover
        2
    niselover  
    OP
       2016-10-15 21:04:49 +08:00
    @kitalphaj tableView 就不闪诶。。
    tuimaochang
        3
    tuimaochang  
       2016-10-15 21:04:58 +08:00
    这……
    paradoxs
        4
    paradoxs  
       2016-10-15 21:10:09 +08:00
    要给 Placeholder 不然肯定会闪的, 要么你就用 sdwebimage
    cielpy
        5
    cielpy  
       2016-10-15 22:13:48 +08:00
    你是 reload 了特定的 indexPath 吗
    heqichang
        6
    heqichang  
       2016-10-15 22:20:19 +08:00
    同求解答:之前也遇到过一样的问题,用的 sdwebimage ,设了 placeholder , reload 后有时会闪有时不会。
    DingSoung
        7
    DingSoung  
       2016-10-15 23:38:37 +08:00
    prepare for reused 函数不要清图片,如果取图片需要很长时间 用个默认图顶着,如果图片设置后会触发自动布局也会引起
    tutuge
        8
    tutuge  
       2016-10-16 13:05:59 +08:00 via iPhone
    就是因为设置了 placeholder 才会闪
    niselover
        9
    niselover  
    OP
       2016-10-16 16:04:19 +08:00
    @paradoxs 用了 sdwebimage 还是闪、、
    niselover
        10
    niselover  
    OP
       2016-10-16 16:04:36 +08:00
    @cielpy 不啊 reload 全部哇
    niselover
        11
    niselover  
    OP
       2016-10-16 16:05:45 +08:00
    @dingsoung 请教一下 prepare for reused 是啥方法
    niselover
        12
    niselover  
    OP
       2016-10-16 16:06:18 +08:00
    @tutuge 没设 placeholder 有时候闪有时候不闪 咋回事
    paradoxs
        13
    paradoxs  
       2016-10-16 16:06:47 +08:00
    @niselover 丢上来看看
    niselover
        14
    niselover  
    OP
       2016-10-16 16:18:58 +08:00
    @paradoxs

    Photo *photo = self.allPhotos[indexPath.item];

    OneAlbumCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:reuseIdentifier forIndexPath:indexPath];

    cell.imageView.image = nil;

    cell.isEditing = collectionView.allowsMultipleSelection;

    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:photo.thumImageUrl]];
    yongSir
        15
    yongSir  
       2016-10-16 16:52:11 +08:00
    不想让他闪
    可以指定 reload 的 index ,也就是不管不刷新
    同时在想办法关闭动画,这种老问题 so 上有很多答案
    比如,给个参考:
    ```swift
    CATransaction.begin()
    CATransaction.setDisableActions(true)
    // update or reload here

    CATransaction.commit()
    ```
    yongSir
        16
    yongSir  
       2016-10-16 16:53:09 +08:00
    不全部刷新 打错了
    niselover
        17
    niselover  
    OP
       2016-10-16 16:56:59 +08:00
    @yongSir 感谢回复 试过了 不顶事 有时候还是闪。。
    DingSoung
        18
    DingSoung  
       2016-10-16 17:21:49 +08:00
    @niselover - (void)prepareForReuse {} 把 cell API 好好看看吧
    ashoka
        19
    ashoka  
       2016-10-17 08:00:58 +08:00 via Android
    cell.imageView.image=nil 去掉试下
    kobe1941
        20
    kobe1941  
       2016-10-17 08:02:47 +08:00
    ```
    // 去掉 reloadData 时的动画
    [UIView performWithoutAnimation:^{
    [weakSelf.collectionView reloadSections:[NSIndexSet indexSetWithIndex:0]];
    }];
    ```
    之前写关于 UICollectionView 的 demo 的时候确实有遇到这种情况,我是这么解决的:
    [点这里]( https://github.com/kobe1941/HFRefresh/blob/master/HFRefresh/HFCollectionViewController.m)
    yiplee
        21
    yiplee  
       2016-10-17 12:46:15 +08:00
    可以不用 collectionView 的 reload ,把要刷新的 cell 通过 indexPath 取出来,然后直接对 cell 做操作。
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     3337 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 34ms UTC 04:57 PVG 12:57 LAX 21:57 JFK 00:57
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86