Two days in a row, I’ve received calls from Clout, trying to get me to sign up for yet another credit card. It seems that no matter how many times you tell the same company you’re not interested, they don’t give up. However, for the first time ever, I actually remembered to ask them to add me to their do-not-call list, and as of today, my telephone number’s been added to the Nation Do Not Call list. As an aside, does it worry anybody that to sign up for the do-not-call list, you must provide an e-mail address?
While this all good, the main reason I decided to write about this, is that for the first time in my life, the unwanted telephone call actually came in handy. No, I’m not looking to apply for another credit card (and I loosely follow Chris’ decision not to purchase from companies that bombard me with unwanted advertisements)! However, since I had forgotten to set my alarm (more precisely, two-alarm alarm clocks overwhelm my alarm clock setting skills), the 8.17 am call awoke me only 17 minutes after I had planned to get up. So, for the first time, and most likely last time, I’d just like to thank tele-marketers for helping me out - even if it was inadvertently.
Q. How can I, using an NSTextField, determine when text has been entered or changed and then react to it?
It sounds like you’re asking how you can, say, toggle a checkbox (NSButton) to the on-state when text has been entered into a text field (NSTextField), akin to the way iTunes sets the checkbox when you modify a tag when editing multiple songs. This is actually quite a simple process and involves using the NSNotificationCenter to tell the system that you would like to be tracking such notifications.
To begin with, you’ll first need to tell the default NSNotificationCenter that you would like to begin receiving notifications each time the text has been changed in a text field. According to Apple’s documentation on the NSTextField, you can request to receive any of the following notifications:
NSControlTextDidBeginEditingNotification
NSControlTextDidChangeNotification
NSControlTextDidEndEditingNotification
In this case, we’re going to use NSControlTextDidChangeNotification as it will take care of letting us know if any text was entered. With this piece of knowledge, all we need to do is add the following code to the awakeFromNib method to tell the system we would like to begin receiving notifications:
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(textDidChange:) name:NSControlTextDidChangeNotification object:nil];
What this code does is tell the system that whenever any NSTextField’s have their contents changed, to send an NSNotification to a method called textDidChange: that we will write later. The observer is the control that will receive the notifcations, in this case it is our controller.
Next, we need to write our textDidChange: method and to do so, we will simply add a new method to our source with the following prototype:
- (void)textDidChange:(NSNotification *)aNotification
Now, whenever any NSTextField’s are modified in our program, this method will be run. By querying the NSNotification, we can determine which control was editied. In the following code, I’m checking to see if the control that sent the notification is called ‘artist,’ and if so, I’m simply setting my checkbox named ‘modifiedArtist’ to checked:
if ([aNotification object] == artist) {
[modifyArtist setState:NSOnState];
}
The last step in this process is to just make sure that you’ve set your connection for delegate in Interface Builder (from your Window to your Controller).
During the development process of my redesigned web site, I had to make a decision whether or not to import my previous blog entries over from MoveableType. On one hand, it would add additional content to my site and make the update seamless. On the other hand, it would require me editing some fifty posts to make sure that they appeared correctly and resizing the images that I had used before. In the end, I decided it was simply not worth it. Looking back at my previous posts, the majority were simply one or two paragraph updates. While interesting, they added little to the overall content of the site and won’t be missed. A few, however, were quite interesting and I’ve decided to save the posts in case later I decide I’d like to re-post them online.
One such post that I felt was both relevant and interesting, was my preview to the iPod Shuffle, where I discussed its merits as a gym tool. As I plan to write a follow up in the next week or so (now that I received the iPod Shuffle and have had a chance to use it), I’ve decided to re-post the article on my site here.
Whoa! Don’t worry, Aram’s web site hasn’t disappeared. In fact, its still available at www.aramk.net! What you’ve stumbled upon, whether accidental or not, is Aram’s current prototype for the next iteration of his web site. It’s a work-in-progress and the time frame for completion is unknown. I’ve just moved to a new hosting company, TextDrive, taking advantage of their limited time offering of lifetime hosting for $399, and have begun investigating the merits of WordPress. So far, both the new host and new content management system appear to be amazing. Plus, for the first time, commenting will be available, so for all the three people who visit my rarely updated web site, you can post whats on your mind. Cheers.
| Archives » | |
| Friends » | |
| Browsing » |
Copyright © 2000 - 2007, Aram Kudurshian. All rights reserved.
Syndicated Feeds: Journal Entries, Journal Comments, and Noteworthy Links.