小编Rad*_*her的帖子

是否可以使用iOS 11拖放功能在UITableView中一次重新排序多个项目/单元格?

我知道在使用new UITableViewDropDelegateUITableViewDragDelegatedelegates 时可以一次重新排序单个项目/单元格,但是是否可以支持处理多个项目/单元格.

例如,在此屏幕截图中,我持有一个项目: 拖动单个项目/单元格

放下牢房就把它放进去了.

然而,当我抓住多个单元格时,我得到了无条目符号,并且单元格不会重新排序: 多项选择拖放,没有输入符号

如果我来自另一个应用程序的多个项目,它可以正常工作,例如从iMessage中拖出多个消息: 多次选择从iMessage拖放

是否可以在仅使用本地项目重新排序表格视图时执行此操作,以便您可以更快地重新排序?

这是我的代码:

UITableViewDragDelegate

extension DotViewController: UITableViewDragDelegate {
    func tableView(_ tableView: UITableView, itemsForBeginning session: UIDragSession, at indexPath: IndexPath) -> [UIDragItem] {
        return [getDragItem(forIndexPath: indexPath)]
    }

    func tableView(_ tableView: UITableView, itemsForAddingTo session: UIDragSession, at indexPath: IndexPath, point: CGPoint) -> [UIDragItem] {
        return [getDragItem(forIndexPath: indexPath)]
    }

    func getDragItem(forIndexPath indexPath: IndexPath) -> UIDragItem {
        // gets the item
    }
}
Run Code Online (Sandbox Code Playgroud)

UITableViewDropDelegate

extension DotViewController: UITableViewDropDelegate {
    func tableView(_ tableView: UITableView, canHandle session: UIDropSession) -> Bool …
Run Code Online (Sandbox Code Playgroud)

drag-and-drop uitableview ios swift ios11

6
推荐指数
1
解决办法
3449
查看次数

是否可以通过扩展中的Swift 4 KeyPaths在UIView上设置属性?

我正在尝试通过扩展程序在UIView上创建一个set方法,这将允许我通过新的Swift 4 KeyPaths设置颜色.如果我执行以下操作,则会收到错误消息Cannot assign to immutable expression of type 'UIColor?'

extension UIView {
    func set(color: UIColor, forKeyPath path: KeyPath<UIView, UIColor?>) {
        self[keyPath: path] = color //  Error: Cannot assign to immutable expression of type 'UIColor?'
    }
}
view.set(color: .white, forKeyPath: \.backgroundColor)
Run Code Online (Sandbox Code Playgroud)

如果我在扩展名之外使用它,它可以正常工作:

let view = UIView()
let path = \UIView.backgroundColor
view[keyPath: path] = .white // Works fine
Run Code Online (Sandbox Code Playgroud)

使用旧式KeyPath也可以正常工作:

extension UIView {
    func set(color: UIColor, forKeyPath path: String) {
        self.setValue(color, forKey: path)
    }
}
view.set(color: .white, forKeyPath: #keyPath(UIView.backgroundColor))
Run Code Online (Sandbox Code Playgroud)

谢谢你的帮助.

uiview ios swift swift4

3
推荐指数
1
解决办法
1262
查看次数

标签 统计

ios ×2

swift ×2

drag-and-drop ×1

ios11 ×1

swift4 ×1

uitableview ×1

uiview ×1