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
heqichang
V2EX  ›  iDev

在 stackoverflow 提了个问题,一直无人回答

  •  
  •   heqichang ·
    heqichang · 2017-03-08 09:09:11 +08:00 · 8320 次点击
    这是一个创建于 2599 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在 stackoverflow 提了个问题,但是苦于自己英文水平,中间 on hold 编辑了几次。这样是不是上面的大牛们都看不到这个问题了?浏览量很少哩。我可以删除旧问题,重新提问吗?

    顺道求 v2 上的老司机看看有人遇到同样的问题吗?😊

    http://stackoverflow.com/questions/42406686/uitableview-will-change-contentoffset-in-ios8-with-swift3-is-this-a-swift3-bug
    第 1 条附言  ·  2017-03-08 22:24:32 +08:00
    问题中文版:
    tableview 里每个 cell 高度不同,加载新的数据 reloadData 后,用 swift3 ios8 下的 tableview 会自动改变 contentOffset ,但是同样的代码逻辑,同样的机器用 swift2 不会改变 contentOffset 。写了个 demo 在这里 https://github.com/heqichang/swift3-tableview-issue
    39 条回复    2019-01-18 11:14:58 +08:00
    bjzhou1990
        1
    bjzhou1990  
       2017-03-08 10:27:24 +08:00
    -2 .....

    在这里用中文描述一遍?
    knight322
        2
    knight322  
       2017-03-08 10:29:48 +08:00
    看到有人回答了哦
    Mine
        3
    Mine  
       2017-03-08 10:33:12 +08:00
    不是有人回答你吗?
    Yc1992
        4
    Yc1992  
       2017-03-08 10:39:43 +08:00
    估计是因为英文太差了所以-2.。。
    bombless
        5
    bombless  
       2017-03-08 10:48:36 +08:00
    ……就你提供的这些信息别人根本无从重现
    paradoxs
        6
    paradoxs  
       2017-03-08 10:50:29 +08:00
    发在那里没意思, 你要是用中文在这里发, 分分钟解决了.
    isCyan
        7
    isCyan  
       2017-03-08 10:55:51 +08:00 via Android   ❤️ 1
    @paradoxs 并不是这样哦
    heqichang
        8
    heqichang  
    OP
       2017-03-08 10:59:34 +08:00
    @bjzhou1990 tableview 里每个 cell 高度不同,加载新的数据 reloadData 后,用 swift3 ios8 下的 tableview 会自动改变 contentOffset ,但是同样的代码逻辑,同样的机器用 swift2 不会改变 contentOffset 。写了个 demo 在这里 https://github.com/heqichang/swift3-tableview-issue
    heqichang
        9
    heqichang  
    OP
       2017-03-08 11:00:26 +08:00
    @knight322 回答的不是我问的问题,估计是我编辑之前没描述准确
    heqichang
        10
    heqichang  
    OP
       2017-03-08 11:02:21 +08:00
    @Yc1992 是啊,重新编辑问题还花了我半天...英文表述是硬伤
    wtser
        11
    wtser  
       2017-03-08 11:33:14 +08:00
    jadecoder
        12
    jadecoder  
       2017-03-08 11:37:14 +08:00
    一个周无回答无评论可以获得一个风滚草徽章, lz 得到了吗?
    heqichang
        13
    heqichang  
    OP
       2017-03-08 11:50:48 +08:00
    @wtser 😄,也发布问题了,还早于 stackoverflow ,就是没人回答才上的 stackoverflow 。 https://segmentfault.com/q/1010000008453554
    heqichang
        14
    heqichang  
    OP
       2017-03-08 11:51:32 +08:00
    @jadecoder 啥?这还能有成就达成?😳
    chipmuck
        15
    chipmuck  
       2017-03-08 11:53:26 +08:00
    @heqichang segmentfault 就别提了,基本没人会去回复的。问题的质量也不高。
    nagato
        16
    nagato  
       2017-03-08 12:00:01 +08:00
    每次 reload 你的 height 都变了?
    xuboying
        17
    xuboying  
       2017-03-08 12:05:32 +08:00 via Android
    so 看问题的。 py 一类的都是秒回
    太独特的问题没回答的。很正常。
    sf 就算了。
    airbob
        18
    airbob  
       2017-03-08 12:26:16 +08:00
    没有复现你的问题,两个 demo 都试了
    heqichang
        19
    heqichang  
    OP
       2017-03-08 14:31:13 +08:00
    @nagato 没有啊, height 的顺序没变,都是一个固有顺序,只是每个 cell 高度不一样
    heqichang
        20
    heqichang  
    OP
       2017-03-08 14:34:01 +08:00
    @airbob 哦?你的测试机型和系统是什么哩?我手上只有三台测试机,所以无法确定覆盖所有版本。我测试有问题的机器是 iphone5s ,系统是 8.4 。其它 ios8 系统没测过。我这还有两台 ios10 的机子就没问题。
    airbob
        21
    airbob  
       2017-03-08 15:41:46 +08:00
    @heqichang 必须用测试机么, simulator 能复现吗?
    heqichang
        22
    heqichang  
    OP
       2017-03-08 16:08:33 +08:00
    @airbob 你是 ios8 的 simulator 吗?我不确定,因为我没在 simulator 测试过,我这里本地只有 ios10 的 simulator ,没下 ios8 的。
    airbob
        23
    airbob  
       2017-03-08 16:13:42 +08:00
    @heqichang 是的我用的 simulator, 手头上没有 iOS8 device
    heqichang
        24
    heqichang  
    OP
       2017-03-08 16:36:55 +08:00
    @airbob 我去下载个旧版本 simulator 试试哈。顺道吐槽下 Xcode 里下载旧版本的 simulator 太慢了。。。😅
    airbob
        25
    airbob  
       2017-03-08 18:17:26 +08:00
    dapeng
        26
    dapeng  
       2017-03-08 18:28:24 +08:00
    楼主,你的中文问题描述呢
    heqichang
        27
    heqichang  
    OP
       2017-03-08 22:25:13 +08:00
    @dapeng 已重新 append 上了
    congeec
        28
    congeec  
       2017-03-08 22:28:27 +08:00 via iPad   ❤️ 1
    @chipmuck 而且在 segfault 上解决了人家的问题,连个赞都没有
    heqichang
        29
    heqichang  
    OP
       2017-03-08 22:28:30 +08:00
    @airbob 是啊,你的看起来没问题,有问题的话,它的 contentOffset 会有比较大的跳跃。话说的我的 simulator 挂机到现在还没下载完。。。
    heqichang
        30
    heqichang  
    OP
       2017-03-08 23:02:37 +08:00
    @airbob 我下载好 iOS8 的模拟器了, iOS 8.4 的系统,可以重现这个问题的。当加载完多余一屏的色块时,会看到 tableview 有明显的跳动,多加载几个色块之后,往上面滑动也会看到明显的跳跃。
    heqichang
        31
    heqichang  
    OP
       2017-03-08 23:07:26 +08:00
    @airbob 这里是我的 log

    https://gist.github.com/heqichang/89e9f2e29f29b1f39627340313510a1b

    注意看里面 446.0 , 554.5 这些地方,明显的有一次大跳跃
    chipmuck
        32
    chipmuck  
       2017-03-08 23:18:53 +08:00   ❤️ 1
    @congeec 给你一个赞!
    InfinitySam
        33
    InfinitySam  
       2017-03-12 14:01:10 +08:00
    楼主,我想问问你 cell height 是算出来的么。。。? 还有视觉上有什么不同,你的意思好像是 reload 后 cell 的垂直位置变化了,对吧?
    heqichang
        34
    heqichang  
    OP
       2017-03-13 10:19:15 +08:00
    @InfinitySam 我随手写的固定的一个高度序列,[150, 500, 150, 150, 150, 300, 100, 300]。是啊,垂直位置发生了变化,但是,同样的代码, 我这里测试,只有在 ios8 ,并且是 swift3 上才会出现这个问题,模拟器 ios8 上也能复现。
    xiabob
        35
    xiabob  
       2017-03-13 17:09:56 +08:00
    是的,我迁移到 swift3 ,在 iOS8 上也有这个问题, func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat 方法调用有问题, IndexPath 不全,你也可以测一下
    heqichang
        36
    heqichang  
    OP
       2017-03-13 18:22:10 +08:00
    @xiabob 是啊,好像是这样的,调 reload 后在 heightForRowAt 方法里的 IndexPath 数目不对,总是少 1 个。你们解决这个问题了吗?
    xiabob
        37
    xiabob  
       2017-03-14 09:56:17 +08:00
    tableView(_ tableView: UITableView, numberOfRowsInSection section: Int)返回 1 , func numberOfSections(in tableView: UITableView) -> Int 返回具体的数目,是可行的,不过局限太多了
    heqichang
        38
    heqichang  
    OP
       2017-03-14 12:00:00 +08:00
    @xiabob 我去!聪明啊!你这方法真可以,把 section 和 row 反一下。真坑爹!幸好正式项目里没有用到多 section ,但只针对 ios 8 来改动的地方还是蛮多的。
    soverflowchina
        39
    soverflowchina  
       2019-01-18 11:14:58 +08:00
    这里肯定有人回答的:
    https://www.stackoverflowchina.com
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1748 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 38ms · UTC 16:36 · PVG 00:36 · LAX 09:36 · JFK 12:36
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.