Macos 在NSTableRowView中单击按钮时AppDelegate崩溃
我正在使用故事板进行OSX开发。我使用的是NSTableView,此表视图的行使用了不同的NStableRowView。这就是逻辑-Macos 在NSTableRowView中单击按钮时AppDelegate崩溃,macos,swift,cocoa,storyboard,nstableview,Macos,Swift,Cocoa,Storyboard,Nstableview,我正在使用故事板进行OSX开发。我使用的是NSTableView,此表视图的行使用了不同的NStableRowView。这就是逻辑- func getRowView(#forIndex:Int) -> NSTableRowView?{ if forIndex == lastSelectedRow{ var storyboard = NSStoryboard(name: "Settings", bundle: nil) var accountC
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
}
}
问题:视图中有一个按钮,其viewcontroller在第行实例化-
var accountController = storyboard?.instantiateControllerWithIdentifier("account") as! CMMAccountViewController
我用CTRl从CMMCountViewController中的那个按钮拖动了一个动作,但每当我点击那个按钮时,应用程序就会崩溃,无法访问。
为什么会这样?如何在NSTableRowView中使用该按钮?问题已解决。问题是accountController是局部变量,一旦使用视图,它就会被释放。我必须保持此引用的活动状态,以避免取消分配此引用