Patrick CARDONA wrote:
Hello,
I am working on an Internet Shortcuts Manager (aka SaveLink).
I associated the same action (statechange:) on my two fields ('name'
and 'link').
If they are not empty, the 'savebutton' should be enabled.
But my button state does never change. Initial state is disabled and
it remains in this state.
I didn't download your project, just reading the code.
Are you sure you get statechange called? is it connected?
Put an NSLog(@"statechange called") and check.
In the class:
@implementation
// (...)
- (IBAction) statechange: (id)sender
{
// We retrieve values from textFileds outlets
NSString *nameLink = [name stringValue];
NSString *urlLink = [link stringValue];
int lenName = [nameLink length];
int lenLink = [urlLink length];
These are unsigned, or better NSUinteger, not int. Won't change, just
nitpick.
if(lenName>0 && lenLink>0)
{
Put an NSLog(@"Enable"); here so you are sure that the condition is
matched and the issue is in setEnabled.
You can easily write this condition as:
if([nameLink length] && [urlLink length])
or for extra paranoids
if((nameLink && [nameLink length]) && (urlLink && [urlLink length]))
It checks that both string are valid and longer than zero. Not
necessary, but it can also be quicker, since it will bail out on a nil
string.
you could also try to trim spaces.
Riccardo