Skip navigation.
 
mlStrange NSTextField behaviour
FROM : Peter Browne
DATE : Tue Dec 21 23:19:49 2004

I have an NSTextField within a window (the window is a custom NSWindow
subclass if this is important) that appears as a sheet for an NSTabView
called MFDtabView. When the sheet is ended by clicking a button, i want
the content of the NSTextField named userNameTextField to be used as an
NSString (the purpose of this is to simulate a 'login' process, where
by the user enters their username which is then checked against a set
of known usernames etc).

However, when the sheet is ended, the content of the NSTextField seems
to be unavailable. The NSLog shows the contents of the textfield to be
NULL which to me suggests a broken connection of some sort. Any ideas?
Here is the relevant code:

- (IBAction)LoginUser:(id)sender    // Called when the login button is
pressed
{
   if ([ModeID isEqualToString:@"2"]) {
   
    [NSApp beginSheet:userNameWindow
            modalForWindow:[MFDtabView window]
            modalDelegate:self
           
didEndSelector:@selector(loginSheetDidEnd:returnCode:contextInfo:)
            contextInfo:NULL];
       }
}

- (IBAction)EndLoginUser:(id)sender    // Called when the OK button in the
resulting sheet window is pressed
{
   // Hide the sheet
   [userNameWindow orderOut:sender];
   
   // Return to normal event handling
   [NSApp endSheet:userNameWindow returnCode:1];
}

- (void)loginSheetDidEnd:(NSWindow *)sheet
            returnCode:(int)returnCode
            contextInfo:(void *)contextInfo;
{
   NSString * username = [userNameTextField stringValue];
   NSLog(@"Now logged in as %@", username);
   
   [usernameMFDDisplay setStringValue:username];    // Display the name of
the currently logged in user
   
   [self checkUserAgainstDatabase];
}

- (void)checkUserAgainstDatabase
{
   NSString * usernameCheck = [knownUsers valueForKey:@"username1"];
   if ([username isEqualToString:usernameCheck]) { NSLog(@"Welcome %@",
username); } else { NSBeep(); NSLog(@"Sorry, user %@ has not been
recognised."); }            
}

Thanks in advance,
Peter

Related mailsAuthorDate
mlStrange NSTextField behaviour Peter Browne Dec 21, 23:19
mlRe: Strange NSTextField behaviour Fritz Anderson Dec 22, 01:30