【问题标题】:Crash in AppDelegate on clicking button in NSTableRowView单击 NSTableRowView 中的按钮时 AppDelegate 崩溃
【发布时间】:2015-09-18 14:53:06
【问题描述】:

我正在使用故事板进行 OSX 开发。我正在使用 NSTableView 并且不同的 NSTableRowViews 用于此表视图的行。这是逻辑-

    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
    }
}

问题:我有一个按钮在视图中,其视图控制器在行实例化 -

  var accountController = storyboard?.instantiateControllerWithIdentifier("account") as! CMMAccountViewController

我让 CTRl 从 CMMAccountViewController 中的该按钮拖动了一个动作,但是每当我单击该按钮时,应用程序就会因 EXE_BAD_ACCESS 而崩溃。 为什么会这样?我应该如何在 NSTableRowView 中使用该按钮?

【问题讨论】:

    标签: macos swift cocoa storyboard nstableview


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2018-10-13
      • 1970-01-01
      • 2021-03-13
      • 2017-06-15
      • 1970-01-01
      • 2013-09-23
      • 1970-01-01
      • 2014-07-24
      • 2011-10-20
      相关资源
      最近更新 更多