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/

相关文章:

macos - 我可以在我的 macOS 应用程序中嵌入第 3 方命令行实用程序并将其提交到 Mac App Store 吗?

python - 如何通过脚本图标上的 "dropping"文件/文件夹将路径名传递给 Python 脚本

swift - “ fatal error :在展开可选值时意外发现nil”是什么意思?

cocoa - 基础工具中的 NSNotificationCenter

cocoa - 从计时器停止 NSRunLoop

objective-c - 窗口出现时未设置标签上的文本

swift - 无法处理全屏 NSWindow 中的按键事件

c++ - 未加载 QMYSQL 驱动程序,已尝试所有提示

swift - 在 Swift 中使用 FFmpeg 库

ios - 显示 gif Swift iOS 时占用大量内存