簡體   English   中英

單擊NSTableRowView中的按鈕時AppDelegate崩潰

[英]Crash in AppDelegate on clicking button in NSTableRowView

我正在使用故事板進行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中使用該按鈕?

問題解決了。 問題是accountController是局部變量,使用視圖后就將其釋放。 我必須保持該參考資料有效,以避免重新分配該參考資料。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM