iOS 9 中可滑动的表格视图单元格 [英] Swipe-able Table View Cell in iOS 9

查看:32
本文介绍了iOS 9 中可滑动的表格视图单元格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的表格列表有一个可滑动的菜单,就像在 iOS 8 中一样(在 iOS 7 中首次引入).

I want my table list to have a swipe-able menu like in iOS 8 (first introduced in iOS 7).

我发现 雷·温德利希 (Ray Wenderlich) 的指南很清楚 关于如何去做,但它是一年零四个月前写的,代码是在 Objective-C 中的.

I've found a Ray Wenderlich guide that is clear on how to do it, but it was written a year and 4 months ago and the code is in Objective-C.

iOS 8 或即将推出的 iOS 9 最终是否在 Apple 的 SDK 中包含此功能?我知道他们多年前内置了滑动以显示删除功能".如果 Apple 的新 iOS 将它放在一个整齐包装的包装中,我不想浪费时间实现修补在一起的代码来模仿 iOS 8 邮件功能.

Did iOS 8 or the upcoming iOS 9 finally include this function in Apple's SDK? I know they made the "swipe to reveal delete function" built-in years ago. I don't want to waste my time implementing patched-together code to mimic the iOS 8 mail function, if Apple's new iOS is going to hand it to me in a neatly wrapped package.

推荐答案

试试这个,针对 Swift 3 更新 (开发者文档)

Try this, updated for Swift 3 (Developer Docs)

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]
}

也实现这个:(你可以让它有条件,但这里一切都是可编辑的)

Also implement this: (You can make it conditional, but here everything is editable)

override func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
    return true
}

这篇关于iOS 9 中可滑动的表格视图单元格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆