Downloading bugs is a bad idea
Posted by matt, Fri Dec 21 06:32:00 UTC 2007
NSProgressIndicators are notorious things, particularly when trying to shove them inside of an NSCell. This has been a thorn in my side since working on managing downloads and also giving feedback as to how they are going.
Problem number one is that there is no easy way to implement an NSProgressIndicator inside of an NSCell. In order to do this, the instance of the NSProgressIndicator needs to be added as a subview to the control view of the NSCell.
This though took many times to figure out with regards to just how to draw the NSProgressIndicator properly and more importantly who had ownership of the NSProgressIndicator.
Though the fun doesn't end there.
The biggest fun came when I tried to remove rows of completed downloads from the NSArrayController subclass. This proved a huge problem as though the rest of the row were deleted, the NSProgressIndicator instances remained.
Eventually, after much frustration and headache, the culprate was found. Every time the drawWithFrame: method of the NSCell subclass was called, I was adding the NSProgressIndicator instance as a subview of the control view. This resulted in many redesigns and refactoring of the code till I found a way of only having one NSProgressIndicator for each row added and even removing it at the correct time.
The final result after many days was a working download window who's objects could be removed once downloaded.
God bless,
Matt.
