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

xcode 6.3.2, UITableViewCell 往左滑动没有红色的删除按钮

  •  
  •   xenme ·
    xenme · 2015-06-02 20:35:01 +08:00 · 3490 次点击
    这是一个创建于 3255 天前的主题,其中的信息可能已经有所发展或是发生改变。
    往左边滑动之后,右边空白
    已经实现了:
    func tableView(tableView: UITableView, commitEditingStyle editingStyle: UITableViewCellEditingStyle, forRowAtIndexPath indexPath: NSIndexPath)
    第 1 条附言  ·  2015-06-02 21:14:32 +08:00

    第 2 条附言  ·  2015-06-02 21:14:52 +08:00
    卡这里两天了
    第 3 条附言  ·  2015-06-02 21:53:22 +08:00
    第 4 条附言  ·  2015-06-03 08:57:04 +08:00
    @shanigan
    @SeanChense
    确实像 @black 所说,TableView 宽带超过屏幕了,改完约束解决了,再次感谢!
    9 条回复    2015-06-03 08:37:38 +08:00
    shanigan
        1
    shanigan  
       2015-06-02 21:28:31 +08:00
    你需要这个delegate来enable slide to delete

    optional func tableView(_ tableView: UITableView, canEditRowAtIndexPath indexPath: NSIndexPath) -> Bool

    另外从截图上来看你的table view已经是在editing mode了,你是不是已经用了

    func setEditing(_ editing: Bool, animated animate: Bool) ?

    如果你要滑动删除的话 tableview.editing has to be NO.
    xenme
        2
    xenme  
    OP
       2015-06-02 21:42:05 +08:00
    @shanigan 第一个已经实现了,直接 return true,而且我看文档,default 都是 edittable,不过我还是实现了。
    setEditing 我也实现了,注释掉之后也是一样。

    往左滑动的话,tableview.editing 应该会自动变成 YES 吧,而且 editingStyle也应该变成 Delete。

    搜了各种删除的教程和视频,应该只要实现之前那一个就 OK 了,不知道是不是 XCODE 或者 Simulator 的 BUG。
    =======
    xcode 6.3.2 (6D2105), Simulator Version 8.3 (SimulatorApp-565.9),没有证书,没法真机测试。
    shanigan
        3
    shanigan  
       2015-06-02 21:46:52 +08:00
    @xenme 你截图中左边的删除按钮显示你的tableview已经是在editing mode了。你向左滑动肯定不会出现删除按钮。这么基本的一个功能是不可能会有bug的。
    xenme
        4
    xenme  
    OP
       2015-06-02 21:53:38 +08:00
    @shanigan 我又补充了一个全的代码
    shanigan
        5
    shanigan  
       2015-06-02 22:14:03 +08:00
    try adding "override" to both delegates?
    xenme
        6
    xenme  
    OP
       2015-06-02 22:25:49 +08:00
    @shanigan 这几个都是实现 DataSource 和 Delegate的 protocol,是不需要 override 的。
    加了 override,xcode 直接报错。Method does not override any method from it's superclass,所以,也不是这个问题。
    black
        7
    black  
       2015-06-03 01:56:34 +08:00   ❤️ 2
    从你提供的线索看来,很大可能是你的 table view 宽度超过了屏幕宽度,检查一下你的布局约束吧。
    shanigan
        8
    shanigan  
       2015-06-03 06:44:27 +08:00   ❤️ 2
    我回到家之后开了一个小的test project,只要你实现了commitEditingStyle那个delegate,滑动删除按钮是肯定会出现的。

    我也觉得@black是正确的,从你的截图来看,你的table cell已经被滑动到左边去了,看不到按钮唯一的解释职能是你的tableview超宽。加一个constraint应该就可以。

    如果你这个view没有其他组件的话,你完全可以直接用UITableviewController,拖拽一个table view到view controller的话你会碰到像这样的麻烦。
    SeanChense
        9
    SeanChense  
       2015-06-03 08:37:38 +08:00 via iPhone   ❤️ 1
    @black 说的应该是正解。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2554 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 12:58 · PVG 20:58 · LAX 05:58 · JFK 08:58
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.