我知道在使用new UITableViewDropDelegate和UITableViewDragDelegatedelegates 时可以一次重新排序单个项目/单元格,但是是否可以支持处理多个项目/单元格.
放下牢房就把它放进去了.
然而,当我抓住多个单元格时,我得到了无条目符号,并且单元格不会重新排序:

如果我来自另一个应用程序的多个项目,它可以正常工作,例如从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) 我正在尝试通过扩展程序在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)
谢谢你的帮助.