macos - 单击 NSTableRowView 中的按钮时 AppDelegate 崩溃

标签 macos swift cocoa storyboard nstableview

我正在使用 Storyboard 进行 OSX 开发。我正在使用 NSTableView ,并且不同的 NSTableRowViews 用于此 TableView 的行。这是逻辑-

    func getRowView(#forIndex:Int) -> NSTableRowView?{
    if forIndex == lastSelectedRow{
        var storyboard = NSStoryboard(name: "Settings", bundle: nil)
        var accountController = storyboard?.instantiateControllerWithIdentifier("account") as! CMMAccountViewController
        accountController.accountData = listOfAccounts[forIndex]
        var rowView = accountController.view as! CMMAccountView
        return rowView
    }
    else{
        var rowView = tableView.makeViewWithIdentifier("accountSeetingsRow", owner: self) as! CMMAccountRowView
        rowView.titleLable.stringValue = listOfAccounts[forIndex].nickname!
        rowView.captionLable.stringValue = listOfAccounts[forIndex].accountDisplayName!
        return rowView
    }
}

问题:我的 View 中有一个按钮,其 View Controller 在行 -

处实例化
  var accountController = storyboard?.instantiateControllerWithIdentifier("account") as! CMMAccountViewController

我已经按 CTRl 从 CMMAccountViewController 中的该按钮拖动了一个操作,但每当我单击该按钮时,应用程序就会因 EXE_BAD_ACCESS 崩溃。 为什么会发生这种情况?我应该如何在 NSTableRowView 中使用该按钮?

最佳答案

问题已解决。问题是 accountController 是局部变量,一旦使用 View ,它就会被释放。我必须保持该引用处于事件状态以避免释放该引用。

关于macos - 单击 NSTableRowView 中的按钮时 AppDelegate 崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31161486/

相关文章:

ios - 是否有适用于 iOS 的可自定义 Cocoa 控件看起来像 Readdle 的日历 iPad 应用程序中的日期/时间选择器?

objective-c - Objective-C 中使用自定义 DNS 服务器进行 DNS 查找

macos - 卸载 ipython mac os x

swift - MyScript Interactive Ink SDK 转换为数学返回?

swift - 在 View Controller 之间传递数据使用从导航 Controller 中嵌入的 View 到 tabbarcontroller 的 segue

ios - 操作表文本始终为灰色(NSAttributedString.Key 不起作用)

internet-explorer - 如何在 Mac 上的 Microsoft Internet Explorer 中测试我的网页?

python - GnuRadio 无法在带有 HackRF One 的 OS X 10.9.4 上运行

objective-c - 在 cocoa 中设置 NSView 和 NSImageView 的背景颜色

objective-c - 从 subview 访问 windowController 的按钮