我正在将
Xcode 7 /
Swift 2.2 mac OS X项目迁移到Xcode 8 / Swift 3,我在我的视图控制器类MyViewController中使用undoManager遇到了一个问题,它有一个函数undo.
在Xcode 7 / Swift 2.2中,这很好用:
undoManager?.prepareWithInvocationTarget(self).undo(data,moreData: moreData) undoManager?.setActionName("Change Data)
在Xcode 8 / Swift 3中,使用https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/AdoptingCocoaDesignPatterns.html推荐的模式
这应该改为:
if let target = undoManager?.prepare(withInvocationTarget: self) as? MyViewController { target.undo(data,moreData: moreData) undoManager?. setActionName("Change Data") }
但是,向MycastController的向下转换始终失败,并且未注册撤消操作.
我错过了一些明显的东西,或者这是一个错误?
prepareWithInvocationTarget(_:)(或在Swift 3中准备(withInvocationTarget :))创建一个隐藏的代理对象,Swift 3运行时无法正常工作.
(您可以将其称为错误,并发送错误报告.)
为了达到你的目的,你不能使用registerUndo(withTarget:handler :)吗?
undoManager?.registerUndo(withTarget: self) {targetSelf in targetSelf.undo(data,moreData: moreData) }
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。