- (void)flagsChanged is not called for webview - objective-c

I have created an editable WebView, and I am trying to write some code in
- (void)flagsChanged:(NSEvent *)theEvent
to detect, if the user presses the option key.
But if I type anything this method is not called. What might cause this problem and how can I solve it?

Have you checked that some other method is not getting the event?
In that case, you should send the event to the next responder, that probably will be your method.

Related

Is there a way to disable sounds (such as "beeps") in my mac app?

I know I need to dig the reason why my app is beeping in the code, etc.
But I was wondering, is there a global setting to disable sounds all over my app screens?
this is very little information to go on, but usually your application is beeping when the responder chain comes up with no object that can respond to an event on the screen or keyboard.
For instance, if you type text in an active view and the view doesn't allow for text editing, the view sends the key down event to its super view. For a view this can end by the NSPanel or NSWindow or BSWindow controller. The last responder in the chain invokes the noResponderFor: method, which, when not implemented, will give a beep. If you don't want it to beep, override this method to do something else.
Based on your information I can't give you any other information.

Custom "undo" for Webview

OK, here's the situation. I have:
A Webview
Lots of NSTextFields
Other unrelated controls
Normally, the Edit > Undo menu item links to First Responder's undo: action. And everything works fine + you can even "undo" while typing in an NSTextField.
Now, what if I want to handle this "undo" action, in a different way, only for my WebView.
I've been thinking of two approaches:
Link the "Undo" item to a custom action and check who is the First Responder. If it's the Webview, then do what needs to be done. Else, "pass" the event to the control. (However, when attempting a [FIRST_RESPONDER performSelector:#selector(undo:)], first it doesn't seem to recognize the selector and last but not least nothing happens.)
Link the "Undo" to the first responder's undo:(as usual), subclass the Webview and add a custom - (void)undo:(id)sender action. In that case though, when the webview is active, the "Undo" item is grayed-out, so I can't do anything whatsoever, not even check whether the custom method would be called.
Suggestions? How would you go about that?
What am I missing?
I think this is the answer: https://developer.apple.com/library/mac/documentation/Cocoa/Reference/WebKit/Protocols/WebEditingDelegate_Protocol/
Also reference this: Removing undo actions for a WebView's NSUndoManager

NSTableView early detection of edit session

I've a NSTableView (view-based) whose delegate (my windowcontroller, in this case) needs to be notified as early as possibile of Text editing session starts.
I've tried with the Text Delegate method
- (BOOL)control:(NSControl *)control textShouldBeginEditing:(NSText *)fieldEditor;
but this not working in my case.
The event gets triggered (and the delegate invoked) if and only if i hit some key in the keyboard.
If, by any chance, i click outside the control without having typed anything, the edit session silently stops without notifying anybody.
Any help is appreciated.
#theAmateurProgrammer
Thank you for your suggestion. Well, what you suggest would do only in case of mouse events. Instead, i need to detect the start edit session event always, also in case of, for example, programmatically triggered editing.
However i've found the solution. I subclass the table view and then i override the validateProposedFirstResponder method.
The responder, actually, is the TextField which is about to start editing.

UITextField losing firstResponder after view appears

I have a UIPageViewController. One page has a single button, and the other page has a UITextField with a button. When the page scrolls to the view with the field, I'd like it to becomeFirstResponder and open the keyboard. Here's what happens:
I call [self.locationQuery becomeFirstResponder] ViewController's viewDidAppear method. But it never opens the keyboard.
I do the same in viewWillAppear, and it appears briefly, but then is quickly dismissed.
If I'm on the page with the text field, and pull the page partway and let it go (without changing pages), self.locationQuery receives focus just fine.
It seems like something else is grabbing firstResponder status from the field, but I haven't the faintest idea what, and why it would only be happening when the page changed (rather than revealed after a failed page turn). Any ideas?
Update
I created a way to crawl the views to see if any other views were, indeed, taking firstResponder (from an answer to this question: Get the current first responder without using a private API). Results:
When I explicitly give first responder to the text field, the method reports it has first responder status.
When I don't, it returns null.
Now I'm even more confused.
I don't really understand the nature of what was causing my issue, but I was able to fix it by wrapping the call in an async dispatch in viewDidAppear:
dispatch_async(dispatch_get_main_queue(), ^{
MapManualViewController *strongSelf = weakSelf;
[strongSelf.locationQuery becomeFirstResponder];
});
This one stole a few hours from my life. Here is the Swift 3.x implementation.
DispatchQueue.main.async(execute: {() -> Void in
let strongSelf: MapManualViewController = self
strongSelf. textField.becomeFirstResponder()
})
I also put it in viewDidAppear

What method is called when user taps outside a popover

A quickie...what (if any) method is called when the user dismisses a UIPopover by tapping outside of it? If I want something to happen at this point, where is my hook?
In UIPopoverControllerDelegate we have delegate method called popoverControllerDidDismissPopover: Read : Doc for greater understanding about how to use it.