[NSView reloadData]:发送到实例的无法识别的选择器

时间:2017-12-11 19:20:04

标签: swift macos xcode9 nsoutlineview

我试图通过在splitView的主端创建一个三级outlineView来学习一些Swift和xcode。退出到reloadData后代码崩溃(见下文)。它成功通过了NSOutlineViewDataSource numberOfChildrenOfItem函数(我预计在发生任何其他事情之前再进行第二次传递)然后使用“[NSView reloadData]:无法识别的选择器发送到实例”错误崩溃。这可能是相关的代码:

import Cocoa

//导入WebKit

class MasterViewController: NSViewController {

@IBOutlet weak var outlineView: NSOutlineView!

var categories = [Category]()

override func viewDidLoad() {
    super.viewDidLoad()

    // Do view setup here.
    if let filePath = Bundle.main.path(forResource: "Subjects", ofType:          "plist"){
        categories = Category.categoryList(filePath)
        print(categories)
    }
    self.outlineView.reloadData()
}

}

//这些是NSOutlineViewDataSource

所需的扩展函数

/ * 返回子孙的数量。  有一点需要注意:item是可选的,将是nil  对于数据模型的根对象。在这种情况下,  类别为零;否则它将包含  对象的父级。对于categoryItem对象,  项目将是一个类别。  * /

extension MasterViewController: NSOutlineViewDataSource {
func outlineView(_ outlineView: NSOutlineView,
                 numberOfChildrenOfItem item: Any?) -> Int {

    if let category = item as? Category {

        return category.children.count
    }else if let categoryItem = item as? CategoryItem {

        return categoryItem.grandchildren.count
    }

    return categories.count
}

这是错误转储(我对这方面的知识不够了解):

[<ProbleMatic.Category: 0x600000048190>, <ProbleMatic.Category: 0x604000049630>, <ProbleMatic.Category: 0x60400004e100>]

2017-12-11 11:16:30.361189-0700 ProbleMatic[11382:4324228] -[NSView reloadData]: unrecognized selector sent to instance 0x6000001237a0

2017-12-11 11:16:30.361701-0700 ProbleMatic[11382:4324228] [General] -[NSView reloadData]: unrecognized selector sent to instance 0x6000001237a0

2017-12-11 11:16:30.365690-0700 ProbleMatic[11382:4324228] [General] (

    0   CoreFoundation                      0x00007fff390b300b
 __exceptionPreprocess + 171

    1   libobjc.A.dylib                     0x00007fff5fc91c76
 objc_exception_throw + 48

    2   CoreFoundation                      0x00007fff3914bcd4
 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132

    3   CoreFoundation                      0x00007fff390293f0
 ___forwarding___ + 1456

    4   CoreFoundation                      0x00007fff39028db8
 _CF_forwarding_prep_0 + 120

    5   ProbleMatic                         0x0000000100001cbc
 _T011ProbleMatic20MasterViewControllerC11viewDidLoadyyF + 1148

    6   ProbleMatic                         0x0000000100001e44
 _T011ProbleMatic20MasterViewControllerC11viewDidLoadyyFTo + 36

    7   AppKit                              0x00007fff3665b632
 -[NSViewController _sendViewDidLoad] + 97

    8   AppKit                              0x00007fff36bffd99
 _noteLoadCompletionForObject + 641

    9   AppKit                              0x00007fff365dfe21
 -[NSIBObjectData nibInstantiateWithOwner:options:topLevelObjects:] + 2042

    10  AppKit                              0x00007fff366db13a
 -[NSNib _instantiateNibWithExternalNameTable:options:] + 679

    11  AppKit                              0x00007fff366dad96
 -[NSNib _instantiateWithOwner:options:topLevelObjects:] + 136

    12  AppKit                              0x00007fff366da06c
 -[NSViewController loadView] + 343

    13  AppKit                              0x00007fff36651f32
 -[NSViewController _loadViewIfRequired] + 75

    14  AppKit                              0x00007fff36651e9d
 -[NSViewController view] + 30

    15  AppKit                              0x00007fff3666c96b
 -[_NSSplitViewItemViewWrapper wrapView] + 94

    16  AppKit                              0x00007fff3666319e
 -[NSSplitViewController _setupSplitView] + 593

    17  AppKit                              0x00007fff36662d15
 -[NSSplitViewController viewDidLoad] + 155

    18  AppKit                              0x00007fff3665b632
 -[NSViewController _sendViewDidLoad] + 97

    19  AppKit                              0x00007fff3665206d
 -[NSViewController _loadViewIfRequired] + 390

    20  AppKit                              0x00007fff36651e9d
 -[NSViewController view] + 30

    21  AppKit                              0x00007fff36aa4cc7
 __67-[NSStoryboardEmbedSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 171

    22  AppKit                              0x00007fff36652015
 -[NSViewController _loadViewIfRequired] + 302

    23  AppKit                              0x00007fff36651e9d
 -[NSViewController view] + 30

    24  AppKit                              0x00007fff36eeaa23
 +[NSWindow windowWithContentViewController:] + 41

    25  AppKit                              0x00007fff3714c44d
 +[NSWindowController windowControllerWithContentViewController:] + 41

    26  AppKit                              0x00007fff36aa4888
 __66-[NSStoryboardShowSegueTemplate newDefaultPerformHandlerForSegue:]_block_invoke + 172

    27  AppKit                              0x00007fff36aa4602
 -[NSStoryboardShowSegueTemplate _perform:] + 275

    28  AppKit                              0x00007fff36da775a
 -[NSApplication(NSResponder) sendAction:to:from:] + 312

    29  AppKit                              0x00007fff3684d933
 -[NSControl sendAction:to:] + 86

    30  AppKit                              0x00007fff3684d85b
 __26-[NSCell _sendActionFrom:]_block_invoke + 136

    31  AppKit                              0x00007fff3684d761
 -[NSCell _sendActionFrom:] + 183

    32  AppKit                              0x00007fff3688ea18
 -[NSButtonCell _sendActionFrom:] + 97

    33  AppKit                              0x00007fff3684bfca
 -[NSCell trackMouse:inRect:ofView:untilMouseUp:] + 2438

    34  AppKit                              0x00007fff3688e75f
 -[NSButtonCell trackMouse:inRect:ofView:untilMouseUp:] + 777

    35  AppKit                              0x00007fff3684aa64
 -[NSControl mouseDown:] + 965

    36  AppKit                              0x00007fff36f46959
 -[NSWindow(NSEventRouting) _handleMouseDownEvent:isDelayedEvent:] + 5891

    37  AppKit                              0x00007fff36f435b0
 -[NSWindow(NSEventRouting) _reallySendEvent:isDelayedEvent:] + 2359

    38  AppKit                              0x00007fff36f4285c
 -[NSWindow(NSEventRouting) sendEvent:] + 497

    39  AppKit                              0x00007fff36da3617
 -[NSApplication(NSEvent) sendEvent:] + 307

    40  AppKit                              0x00007fff36604d9d
 -[NSApplication run] + 812

    41  AppKit                              0x00007fff365d3f1a
 NSApplicationMain + 804

    42  ProbleMatic                         0x000000010000f50d
 main + 13

    43  libdyld.dylib                       0x00007fff60881115
 start + 1

    44  ???                                 0x0000000000000003
 0x0 + 3

)

有什么建议吗?提前谢谢。

1 个答案:

答案 0 :(得分:0)

您的插座可能与大纲视图不相关(很可能是它的超级视图)。

您可以查看...

  • 将鼠标悬停在出口圈
  • ctrl 点击视图层次结构中的大纲视图。

enter image description here