NSFormatter degates (was textShouldEndEditing Issues)
NSFormatter degates (was textShouldEndEditing Issues)
- Subject: NSFormatter degates (was textShouldEndEditing Issues)
- From: "Huyler, Christopher M" <email@hidden>
- Date: Mon, 15 Dec 2003 15:02:31 -0500
- Thread-topic: NSFormatter degates (was textShouldEndEditing Issues)
Ok, so I have tried another approach by using
control:didFailToFormatString:errorDescription delegate. However, I
have the same problem. I even tried to simplify it.
1) I create a text field in a Preference Pane.
2) I add a standard Number Formatter inside IB and set the minimum to 1
and the maximum to 131072.
3)I set the text field's delegate to my class which responds to
"control:didFailToFormatString:errorDescription".
4)I implement "control:didFailToFormatString:errorDescription" inside my
class:
- (BOOL)control:(NSControl *)control
didFailToFormatString:(NSString *)string
errorDescription:(NSString *)error
{
NSAlert *alert;
alert = [[NSAlert alloc] init];
[alert setMessageText:
_LocalizedString(@"INVALID_PORT_ALERT_MESSAGE")];
[alert setInformativeText:error];
[alert beginSheetModalForWindow:[control window]
modalDelegate:self
didEndSelector:NULL
contextInfo:NULL];
return NO;
}
5) Compile and debug
What happens? Well If I enter 0 in the text field then click on a
different text field, the sheet pops up. When I click OK I am brought
right back to the text field to make changes. Great. When I enter
Cmd-Q the sheet pops up but while the sheet is up the value is returned
to its original state. Not Great. When I click OK the text field is no
longer the first responder. If I enter Cmd-Q again, System Preferences
exits.
SO what am I looking for? Open up the Network Preference Panel and edit
your DNS server settings. Enter an invalid DNS server (eg. "abc") and
click on something else...anything...the sheet pops up. Great. Now
enter Cmd-Q. The sheet pops up but the value stays and it brings you
back after you click ok. Enter Cmd-Q again...same thing happens.
What delegate function do I need to implement to make sure the user is
brought back to the text field in question? I have tried the above, I
have tried textShouldEndEditing.
-----Original Message-----
From: email@hidden
[
mailto:email@hidden] On Behalf Of Daniel Todd Currie
Sent: Friday, December 12, 2003 6:20 PM
To: email@hidden
Subject: Re: textShouldEndEditing Issues!
Sounds to me like you'd be better off with an NSFormatter.
On 2003 Dec 12, at 11:05, Huyler, Christopher M wrote:
>
Perhaps my previous post was not refined enough. I have a preference
>
pane with several text fields in it. Once the user edits a field, I
>
want to check the format of it as soon as they try to do something
>
else,
>
whether it is quitting the System Preferences App, selecting a
>
different
>
Preference Pane, or just changing the current tab of my pane. I am
>
trying to do this with "- (BOOL)control:(NSControl *)control
>
textShouldEndEditing:(NSText*)text" but it is not working how I want.
>
If the function is going to fail I pop up a modal sheet using
NSAlert's
>
beginSheetModalForWindow function.
>
>
These are the limitations I am running into:
>
1) The user edits then enters Cmd-Q to quit. I get the alert sheet
the
>
first time. If the user clicks "OK" then enters Cmd-Q again, it lets
>
them quit...textShouldEndEditing doesn't get called again.
>
2) The user attempts to change the current Panel. The following code
>
works the first time:
>
- (NSPreferencePaneUnselectReply)shouldUnselect {
>
return ([[NSApp keyWindow] isSheet]) ? NSUnselectCancel :
>
NSUnselectNow;
>
}
>
But after it runs, my textField looses its first responder status
>
meaning if the user tries to change the current panel again, it will
>
work. The invalid entry is left in the textField.
>
>
I know there is a work-around because Apple's Network Control Panel
>
does
>
it when you try to put in an invalid DNS Server. You cannot do
>
anything
>
else until you fix it.
>
>
Is there another delegate function I should be implementing? Does
this
>
have anything to do with using the Window's default field editor?
>
>
>
--
>
Christopher Huyler
>
Computer Associates Intl.
>
mailto:email@hidden
>
_______________________________________________
>
cocoa-dev mailing list | email@hidden
>
Help/Unsubscribe/Archives:
>
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
>
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.