Evil bug #1299

I recently had to deal with this nasty bug on Mac OS 10.3.9 that only showed up when you prompted an Alert dialog box during a NSTableView selectionShouldChange method.

Here’s what would happen. You have a NSTableView filled with your items. When the user selected any one of the rows, the selection of that row would update other controls on the UI with the value that was specific to that row selection. If the user made changes to the controls and selected another row from the NSTableView, the selectionShouldChange method would check to see if the controls have been changed and asks the user if they want to save their changes before continuing. It doesn’t matter what answer they select because once the NSAlert dialog box was dismissed, the NSTableView ceases to get any messages.

The weird thing is, if you actually click anywhere on the application, the NSTableView actually receives the tableSelectionDidChange message. This problem doesn’t happen in 10.4, nor did it happen in 10.5.

So how did I actually fix this bug? Believe it or not, I had to use Carbon to click on the Window. It didn’t matter what Cocoa workaround I used, nothing, I mean NOTHING, worked. I used Carbon to get the Rect of the Window, offset my mouse by 2 pixels, clicked the Window without moving the mouse and Viola! the problem was solved.

This is one of those fixes that I am not proud off because it does not feel like clean code. However, it did fix the bug and in the end, that is what matters.

 

Leave a Reply

Your email address will not be published. Required fields are marked *