Post

Replies

Boosts

Views

Activity

Reply to Memory leak with [NSMutableData appendData:]
Finally I have to re-invent the wheel to solve this mysterious memory leak which I cannot control without the wheel. I am not sure if it is too bold to declare that NSData has serious problems with memory footprint, but... After I devised my own memory management facility (a smart buffer class), the memory footprint drops drastically and stops growing continuously. This is observed for several days.
May ’24
Reply to When to call noteHeightOfRows when cell view changes size?
I did much search on the web and found no answer. The only clue to my question is that I have use another "template" tableview that is identical to the inner tableview. Finally I devised a working solution, I posted here for the purpose of helping others who may have the same/similar problem. Note there is a little trick about calculating the actually row height - you have to include height of the template tableview's header view. func tableView(_ tableView: NSTableView, heightOfRow row: Int) -> CGFloat { if tableView is DetailsTableView { return tableView.rowHeight } if let rowHeight = rowHeights[row] { return rowHeight } let item = categorizedItems[row] if sizingTableView == nil { var objects: NSArray! detailsNib!.instantiate(withOwner: nil, topLevelObjects: &objects) for object in objects { if let sizingCellView = object as? DetailsCellView { sizingTableView = sizingCellView.tableView sizingTableView.delegate = self sizingTableView.dataSource = self sizingTableView.isHidden = true sizingTableView.enclosingScrollView?.setFrameSize(NSSize.zero) self.view.addSubview(sizingTableView) break } } } print("<", sizingTableView.bounds.height) sizingTableView.row = row sizingTableView.files = item.files sizingTableView.reloadData() print(">", sizingTableView.bounds.height) var rowHeight = sizingTableView.bounds.height + (sizingTableView.headerView?.bounds.height ?? 0.0) + summaryTableView.intercellSpacing.height rowHeights[row] = rowHeight if rowHeight > MaxRowHeight { let trailingHeight = (sizingTableView.bounds.height / Double(item.files.count)) * Double(TrailingRowCount) if rowHeight - MaxRowHeight < trailingHeight { // Try reserve height for some rows to let scrollbar look more natural. rowHeight = max(0, MaxRowHeight - trailingHeight) } else { rowHeight = MaxRowHeight } } return max(rowHeight, summaryTableView.rowHeight) }
Mar ’24
Reply to How let scroll event 'sink' to parent view?
I found a solution myself, after days of researching and experiments. It's related to another question "How tell if NSTableView is already displaying its last row entirely?". // For the inner tableview's scrollview class MyScrollView: NSScrollView { var onScrollWheel: EventHandler! override func scrollWheel(with event: NSEvent) { super.scrollWheel(with: event) // In onScrollWheel, determine if vertical scrollbar is hidden or at top/bottom, // then delegate this event to the outer tableview: // outerTableView.scrollWheel(with: event) onScrollWheel?(event) } }
Mar ’24
Reply to What's the unit in NSView coordinate system
Maybe my question is too general. I have a need to calculate all width of an NSTableView. However, I found that total width of all columns is far less than NSTableView.bound.width: let width = tableView.tableColumns.reduce(0) { ac, col in ac + col.width } print(width, tableView.bounds.width) This is true even I manually adjust last column so that it fills the gap between the column and tableview right border. -----------| <- table right border last column| -----------| So I assume NSTableColumn.width and NSView.bounds.width are using different units.
Mar ’24
Reply to Any way to keep app running while keep main window hidden?
Ah, I found out why, though it's a little embarrassing... After so many years, I realized that NSApp.mainWindow is dynamic - it can be any window that has the key focus! I have to create a global variable to keep instance of the initial window (as designed in main storyboard). var mainWindow: NSWindow? // Set in MainWC.windowDidLoad class AnotherWC: NSWindowController, NSWindowDelegate { override func windowDidLoad() { super.windowDidLoad() print(self.className, #function) } func windowShouldClose(_ sender: NSWindow) -> Bool { print(self.className, #function) return true } func windowWillClose(_ notification: Notification) { print(self.className, #function) print(mainWindow ?? "mainWindow is nil") mainWindow?.orderFront(nil) } }
Mar ’24
Reply to Where is the Web entry for app iCloud SDK
I have found where the Web entry is. I have to enable CloudKit service in project settings. Now I have another problem - I accidentally created several database containers (long time ago out of curiosity by clicking a button that says "Enable ClouldKit" or something similar). But I cannot find a way to delete the garbage items. The only way is to hide them in the CloudKit management Web UI.
Feb ’24