How to detect every UI object posted

I am still learning Objective C / Cocoa and I am creating a program with a simple interface. This interface has an NSTextField that has this delegate:

- (void) controlTextDidChange: (NSNotification *) obj{
    //Some code here
}

      

When the user changes the text of any of these NSTextFields, the program must check if the number inside the NSTextField is an integer. If the provided string is not an Integer, I want to display an error dialog and each NSTexField failed, as I have multiple NSTextFields associated with this method.

My question is, how can I detect that each UI object has sent a message to the controlTextDidChange method?

Thanks in advance.

+3


source to share


2 answers


- (void)controlTextDidChange:(NSNotification *)anotif
{
    if ([anotif object]==field1)
    {
        // field1 processing
    }
    else
    {
        // field2 processing
    }
}

      



With controlTextDidChange with two nstextfields - calling different selectors

+2


source


If you don't have subordinate UITextField elements as properties, you can set a tag for each subset of UITextField for @Bruno code like this:



- (void)controlTextDidChange:(NSNotification *)anotif
{
    UITextField *textField = (UITextField *)[anotif object];
    if (textField.tag == 1)
    {
        // field1 processing
    }
    else
    {
        // field2 processing
    }
}

      

+1


source







All Articles