iOS 9 中可滑动的表格视图单元格

2024-05-22

我希望我的表格列表具有像 iOS 8 中那样的可滑动菜单(首次在 iOS 7 中引入)。

我找到了清晰的 Ray Wenderlich 指南 http://www.raywenderlich.com/62435/make-swipeable-table-view-cell-actions-without-going-nuts-scroll-views关于如何做到这一点,但它是一年零四个月前写的,代码是用 Objective-C 编写的。

iOS 8 或即将推出的 iOS 9 最终是否在 Apple 的 SDK 中包含了此功能?我知道他们几年前就内置了“滑动显示删除功能”。如果 Apple 的新 iOS 将以包装整齐的包裹形式将其交给我,我不想浪费时间来实现修补在一起的代码来模仿 iOS 8 邮件功能。


试试这个,已更新为 Swift 3 (开发者文档 https://developer.apple.com/reference/uikit/uitableviewdelegate/1614956-tableview)

override func tableView(_ tableView: UITableView, editActionsForRowAt: IndexPath) -> [UITableViewRowAction]? {
    let more = UITableViewRowAction(style: .normal, title: "More") { action, index in
        print("more button tapped")
    }
    more.backgroundColor = .lightGray
    
    let favorite = UITableViewRowAction(style: .normal, title: "Favorite") { action, index in
        print("favorite button tapped")
    }
    favorite.backgroundColor = .orange
    
    let share = UITableViewRowAction(style: .normal, title: "Share") { action, index in
        print("share button tapped")
    }
    share.backgroundColor = .blue
    
    return [share, favorite, more]
}

还要实现这个:(您可以将其设置为有条件的,但这里一切都是可编辑的)

override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

iOS 9 中可滑动的表格视图单元格 的相关文章

随机推荐