错误:"无法识别的选择器发送到实例"点击按钮时

时间:2015-09-17 09:41:23

标签: objective-c cocoa

请让我告诉你我在做什么。

  1. 我有一个窗口,其中包含NSView" MainContainer "
  2. 在窗口的时候,我正在添加一个自定义视图" 选项"在窗口的NSView中
  3. 客户视图上有一个按钮" 选项"命名" 客户详细信息"
  4. 在客户详细信息上,点击>>删除当前视图(选项)并加载新视图(客户详细信息视图)。我的工作方式如下:

    NSViewController* cdv = [[CustomerDetailsView alloc] init];
    NSView* MainView = [[self view] superview];
    [[self view] removeFromSuperview];
    [MainView  addSubview:[cdv view]];
    

    现在的问题是,最后一个视图(客户详细信息视图)有一些按钮,没有人工作,我收到的错误是" 无法识别的选择器发送到实例&# 34 ;.请让我知道我该怎么办? enter image description here enter image description here

    2015-09-17 15:45:37.872 TechHeal[5058:125394] not start
    2015-09-17 15:46:05.452 TechHeal[5058:125394] -[NSSnapshotContextSignature encryptClick:]: unrecognized selector sent to instance 0x6080000e5c80
    2015-09-17 15:46:05.452 TechHeal[5058:125394] -[NSSnapshotContextSignature encryptClick:]: unrecognized selector sent to instance 0x6080000e5c80
    2015-09-17 15:46:05.464 TechHeal[5058:125394] (
        0   CoreFoundation                      0x00007fff9834a03c __exceptionPreprocess + 172
        1   libobjc.A.dylib                     0x00007fff8e54c76e objc_exception_throw + 43
        2   CoreFoundation                      0x00007fff9834d0ad -[NSObject(NSObject) doesNotRecognizeSelector:] + 205
        3   CoreFoundation                      0x00007fff98292e24 ___forwarding___ + 1028
        4   CoreFoundation                      0x00007fff98292998 _CF_forwarding_prep_0 + 120
        5   libsystem_trace.dylib               0x00007fff95ef2cd7 _os_activity_initiate + 75
        6   AppKit                              0x00007fff9127eeb1 -[NSApplication sendAction:to:from:] + 452
        7   AppKit                              0x00007fff91294946 -[NSControl sendAction:to:] + 86
        8   AppKit                              0x00007fff91294862 __26-[NSCell _sendActionFrom:]_block_invoke + 131
        9   libsystem_trace.dylib               0x00007fff95ef2cd7 _os_activity_initiate + 75
        10  AppKit                              0x00007fff912947bf -[NSCell _sendActionFrom:] + 144
        11  libsystem_trace.dylib               0x00007fff95ef2cd7 _os_activity_initiate + 75
        12  AppKit                              0x00007fff91292cb3 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2821
        13  AppKit                              0x00007fff912eb34f -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 770
        14  AppKit                              0x00007fff91291366 -[NSControl mouseDown:] + 714
        15  AppKit                              0x00007fff917fb2dc -[NSWindow _reallySendEvent:isDelayedEvent:] + 14125
        16  AppKit                              0x00007fff9118ac86 -[NSWindow sendEvent:] + 470
        17  AppKit                              0x00007fff91187212 -[NSApplication sendEvent:] + 2504
        18  AppKit                              0x00007fff910b0b68 -[NSApplication run] + 711
        19  AppKit                              0x00007fff9102d244 NSApplicationMain + 1832
        20  TechHeal                            0x00000001000048e2 main + 34
        21  TechHeal                            0x0000000100001224 start + 52
        22  ???                                 0x0000000000000003 0x0 + 3
    )
    (lldb) 
    

    PS:如果我直接加载客户详细信息,那么它的工作正常,但如果我从另一个视图加载它,那么它无法正常工作。

1 个答案:

答案 0 :(得分:1)

您似乎正在创建Shape控制器,查看其视图,然后让控制器超出范围。假设在该控制器中实现了CustomerDetailsView,问题是当它被调用时,该对象已经被释放。消息被传递给现在占用大块内存的任何内容。

尝试使encryptClick成为您发布的代码中cdv的强大属性,以便它能够处理事件。