Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

xiaohuli170

macrumors newbie
Original poster
Jan 13, 2009
27
0
When I clicked on the textfield,I want to open a panel. I think that I should use a delegate method to respond the clicked event. I found that the method - (void)textDidBeginEditing:(NSNotification *)aNotification not work , and then the method - (void)controlTextDidBeginEditing:(NSNotification *)aNotification worked ,but I found this method worked when I edited the textfield not to cliked it ,why? and that when I edited the textfield again ,This method not to work ,why?
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
NSTextFields don't by default handle clicking - that's what buttons are for :)

If you want this behavior, subclass it and override mouseDown.
 

xiaohuli170

macrumors newbie
Original poster
Jan 13, 2009
27
0
Sorry , I don't know what your means is . can you explain your answer in details.Thanks a lot.
 

GorillaPaws

macrumors 6502a
Oct 26, 2003
932
8
Richmond, VA
Sorry , I don't know what your means is . can you explain your answer in details.Thanks a lot.

What he's saying is that the behavior you're looking for (opening a panel when clicking on a NSTextField) isn't something NSTextFields are really designed to do. The typical pattern is to use an NSButton to bring up a panel. If you really need this behavior to work in this manner then you can subclass the NSTextField and override the mouseDown method in your own custom class to bring up your panel instead of what the normal behavior of that method is (selecting the field--I'm assuming).

Edit: Typically, it's a bad idea to alter the default behaviors of standard UI elements. Users expect things to happen in a certain way when they interact with the GUI. Violating those expectations can lead to confusion and possibly even concern that your app is broken/bugged. In other words, you might want to re-think your design decisions a bit to see if this is the best implementation.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.