How to watch for changes in [NSCursor currentCursor]? - objective-c

I've got an app with a custom cursor which I achieved using a custom wrapper for NSCursor (most of the main code is designed to be OS portable, so above that I pretend the NSCursor is a Windows-style cursor). I'm having a few issues with the cursor not changing back to my custom one when the user cmd+tabs back into the window, and I'd like to see what is changing the value of currentCursor. Everywhere I've tried to set breakpoints has given me nothing so far.
So, I was wondering if there was a way (in Xcode) to break as soon as the value of [NSCursor currentCursor] changes. Is this possible? Is this kind of data accessible to my app?
Thanks - I hope I've made myself clear. It's quite hard to explain when I'm not even sure what I want to do!

NSCursor has a class method currentSystemCursor that will give you what you need in 10.6 and later.

Related

Quick one: Programmatic Animations with Windows Store

Is this really the proper and only way to programmatically set the target of an animation in a Windows Store app?
Storyboard.SetTarget(animation, someElement);
Storyboard.SetTargetProperty(animation, "Width");
It just seems odd not to use an instance method or property on either a Timeline or Storyboard.
It's the programming equivalent of reaching in your car window and using the interior handle to open the door.
Luke
It is the correct way, yes. I do agree it could be made simpler, but it is how it has been since WPF.

Changing the text on a button when a tab is selected in a tabview

I'm trying to learn objective-c by making a GUI application using Xcode 3. I'm wondering if it is possible to change the text of a button outside of a tab view depending on which tab in the tabview is selected? As I said I am trying to learn objective-c so please act as though I know next to nothing in your answer. I should probably mention that I tried making a NSObject and tried to define an IBAction in a .h and .m file but that didn't seem to work. (I have tried setting some breakpoints in those files none of which were ever reached leading me to think something isn't wired the way think it is.)
Sorry for the long winded explanation.
Thanks for all the help!
I actually figured it out. What I needed was object delegation, this page, and of course Google to help get the correct syntax for the actual implementation.

Why does the execution order of touchesBegan, target-action and touchesEnded change with fast touches of UIButton?

UPDATE: With the blush of shame I discovered that the order had nothing to do with the speed of tapping. I was calling the visual code before the super touchesEnded:withEvent call, which was why if you tapped really fast, the display never got a chance to draw the highlighted state before being dismissed again. Because the code that was actually causing the main thread to block just a few milliseconds, the highlighted state would stay visible until the main thread unblocked again, where as if you tapped really fast, it looked like nothing happened at all. Moving the super call up to the top of the overridden method fixed it all. Sorry, if any moderator sees this post it can be deleted. shame
This problem must have been asked a 1000 times at SO, yet I can't find the explanation to match my specific issue.
I have a UIButton subclass with a custom design. Of course the design is custom enough that I can't just use the regular setSomething:forControlState: methods. I need a different backgroundcolor on touch, for one, and some icons that need to flash.
To implement these view changes, I (counter-intuitively) put the display code in (A) touchesBegan:withEvent and (Z) touchesEnded:withEvent:, before calling their respective super methods. Feels weird, but it works as intended, or so it seemed at first.
After implementing addTarget:action:forControlEvents was used to bind the UIControlEventTouchUpInside to the method (X) itemTapped:, I would expect these methods to always fire in the order (A)(X)(Z). However, if you tap the screen real fast (or the mouse in simulator), they fire in the order (A)(Z)(X). Where (A) and (Z) follow each other in such rapid succession, that the whole visual feedback for tapping is invisible. This is unwanted behavior. This also can't be the way to go, for so many apps need similar behavior, right?
So my question to you is: What am I doing wrong? One thing I'm guessing is that the visual appearance of the buttons shouldn't be manipulated in the touchesBegan:withEvent and touchesEnded:withEvent, but then where? Or am I missing some other well known fact?
Thanks for the nudge,
Eric-Paul.
I don't know why the order is different, but here's 2 suggestions to help deal with it.
What visual changes are you making to the button? If it's things like changing title/image/background image, you can do all this by modifying the highlighted state of the button. You can set a few properties like title and background image per-state. When the user's finger is down on the button, the highlighted state is turned on, so any changes you make to this state will be visible at this time. Do note that if you're making use of the selected state on the button, then you'll need to also set up the visual appearance for UIControlStateHighlighted|UIControlStateSelected, otherwise it will default back to inheriting from Normal when both highlighted & selected are on.
The other suggestion is to ditch touchesBegan:withEvent: and touchesEnded:withEvent: and switch over to using the methods inherited from UIControl, namely beginTrackingWithTouch:withEvent: and endTrackingWithTouch:withEvent:. You may also want to implement continueTrackingWithTouch:withEvent: and use the touchInside property to turn off your visual tweaks if the touch leaves the control.

WebView Cocoa control crashing on window close

I get a crash in WebEditorClient::clearUndoRedoOperations which is trying to access -[WebView(WebViewEditing) undoManager] when I close the main window of an NSDocument that contains a webview with a text editor in it. It only happens when there is an undo-able state. Seems like a bug in Cocoa, but I might be doing something wrong. Any ides why this might be going on? The web view is in a nib and not created programmatically, so I'm not sure what I can do to even begin fixing this.
Well, removing it from superview prior to calling close on the document seems to have fixed it. Still, that doesn't explain what was going on, but just putting it here in case other people have this problem.

Can't make empty selection in NSTableView

I don't know how it happened, but all of a sudden in my table view I can't make an empty selection anymore. Like a table view row always has to be selected, and it can't be deselected by clicking somewhere else in the table view. I can select a different row, but I can't make an empty selection.
In the Interface Builder attributes for the table view empty selection is enabled, so I don't know where to look next. The one major change I made was that I installed OS X Snow Leopard. I'm not sure if this issue has something to do with that.
Thanks
I struck this exact same issue (I am using XCode 4.2 but compiling against the 10.6sdk). NSOutlineView::deselectAll just was not deselecting things. I have a fairly complex NSOutlineView which exhibits the same behavior. I had a look on the apple developer forums and other places to try and work around this issue. However in the end working around this for me was very simple and I could just use:
- (void) myDeselectAll
{
[self selectRowIndexes:[NSIndexSet indexSet] byExtendingSelection:NO];
}
Try doing it programmatically with the setter method setAllowsEmptySelection:. Alternatively, try disabling empty selection in IB, saving, then enabling it, saving one more time. That might fix it.
Also make sure that something in tableView:shouldSelectRow: isn't stopping you from it (provided you've implemented this delegate method).
This is a bit old, but for those who need an answer to this:
Use the interface builder and mark the array controller. remove checkmark "avoid empty selection".
If not done so, create an outlet for the array controller. Here I have called it DocumentArrayController.
then to empty selection:
[_DocumentArrayController removeSelectionIndexes:
[_DocumentArrayController selectionIndexes]];
Do you have your columns bound to an array controller? If so, check the controller's attributes.
I'm not allowed to say much more than this: It seems to be a problem with 10.6 specifically