ios - NSUndoManager错误,“无法识别的选择器已发送到实例”

标签 ios swift

在iOS9应用程序中实现NSUndoManager的工作。当前的撤消代码如下:

func setActiveColorData(colorData: ColorData) {
    if colorData != activeColorData {
        print(self)
        undoManager?.registerUndoWithTarget(self, selector: "setActiveColorData:", object: activeColorData!)
        undoManager?.setActionName("Change color")
        print("Set undo action")

        activeColorData = colorData
    }
}


ColorData只是一个简单的类,其中包含三个浮点(色相,饱和度,亮度)和一些实用程序方法。

一切正常,包括摇晃手势,该手势会弹出撤消提示。但是,一旦您单击“撤消”,应用程序就会崩溃并出现以下错误:

2016-02-25 16:26:58.225 Color[89399:5503615] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[Color.PickerViewController setActiveColorData:]: unrecognized selector sent to instance 0x7fa080776820'
*** First throw call stack:
(
    0   CoreFoundation                      0x0000000105b75e65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x0000000108159deb objc_exception_throw + 48
    2   CoreFoundation                      0x0000000105b7e48d -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
    3   CoreFoundation                      0x0000000105acb90a ___forwarding___ + 970
    4   CoreFoundation                      0x0000000105acb4b8 _CF_forwarding_prep_0 + 120
    5   Foundation                          0x00000001066b2feb -[_NSUndoStack popAndInvoke] + 261
    6   Foundation                          0x00000001066b2162 -[NSUndoManager undoNestedGroup] + 424
    7   UIKit                               0x0000000106c46813 -[UIApplication alertView:clickedButtonAtIndex:] + 151
    8   UIKit                               0x0000000106f63589 -[UIAlertView _prepareToDismissForTappedIndex:] + 136
    9   UIKit                               0x0000000106f62fc7 __35-[UIAlertView _prepareAlertActions]_block_invoke50 + 53
    10  UIKit                               0x0000000106f54572 -[UIAlertController _dismissAnimated:triggeringAction:triggeredByPopoverDimmingView:] + 133
    11  UIKit                               0x0000000107604eb6 -[_UIAlertControllerView _handleActionSelectionGestureRecognizer:] + 694
    12  UIKit                               0x000000010711ee73 _UIGestureRecognizerSendTargetActions + 153
    13  UIKit                               0x000000010711b4e5 _UIGestureRecognizerSendActions + 162
    14  UIKit                               0x00000001071194e2 -[UIGestureRecognizer _updateGestureWithEvent:buttonEvent:] + 843
    15  UIKit                               0x00000001071219a0 ___UIGestureRecognizerUpdate_block_invoke904 + 79
    16  UIKit                               0x000000010712183e _UIGestureRecognizerRemoveObjectsFromArrayAndApplyBlocks + 342
    17  UIKit                               0x000000010710f101 _UIGestureRecognizerUpdate + 2634
    18  UIKit                               0x0000000106ca6f8a -[UIWindow _sendGesturesForEvent:] + 1137
    19  UIKit                               0x0000000106ca81c0 -[UIWindow sendEvent:] + 849
    20  UIKit                               0x0000000106c56b66 -[UIApplication sendEvent:] + 263
    21  UIKit                               0x0000000106c30d97 _UIApplicationHandleEventQueue + 6844
    22  CoreFoundation                      0x0000000105aa1a31 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
    23  CoreFoundation                      0x0000000105a9795c __CFRunLoopDoSources0 + 556
    24  CoreFoundation                      0x0000000105a96e13 __CFRunLoopRun + 867
    25  CoreFoundation                      0x0000000105a96828 CFRunLoopRunSpecific + 488
    26  GraphicsServices                    0x000000010a416ad2 GSEventRunModal + 161
    27  UIKit                               0x0000000106c36610 UIApplicationMain + 171
    28  Color                               0x00000001052a2a7d main + 109
    29  libdyld.dylib                       0x0000000108c9992d start + 1
    30  ???                                 0x0000000000000001 0x0 + 1
)
libc++abi.dylib: terminating with uncaught exception of type NSException


我已经检查了PickerViewController实例和内存位置是否匹配(从print(self)行,在本例中为0x7fa080776820)。知道为什么它不能调用该选择器吗?或者是别的什么?谢谢!

最佳答案

当内存快用完时,我在照片编辑应用程序中遇到相同的崩溃。当我收到内存警告时,我清除了撤消管理器,但就我而言,我认为会发生崩溃是因为从撤消管理器下删除了内存。

如果相关:https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/UndoArchitecture/Articles/CleaningUndoStack.html

关于ios - NSUndoManager错误,“无法识别的选择器已发送到实例”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35633063/

相关文章:

ios - 使用 swift 在大量 map 上的 xcode 中构建时间极长

swift - 了解 ARKit 世界变换矩阵

ios - 未以编程方式检测 Dismiss Popover

ios - Swift-如何从UITableViewCell中的按钮调用UIVIewController

ios - 为什么在创建新对象时alloc和init可能返回不同的对象?

ios - kSecAttrAccount 和 kSecAttrGeneric

ios - 如何将UIActivityIndi​​catorView添加到UITableView的底部,并在加载时切换它

ios - 如何将 Firebase 下载文件与进度 View 链接起来?

swift - 可以用 NSOrdered 集编码吗?

swift - 目标-C 方法 'imagePickerController:didFinishPickingMediaWithInfo:'