我正在使用 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/