Can't Type in TextField

Discussion in 'Mac Programming' started by CaptainZap, May 29, 2008.

  1. CaptainZap macrumors regular

    Joined:
    Jan 17, 2007
    #1
    I created a NSWindow subclass and all I did was add this method (You can probably do all this without subclassing it but it works)
    Code:
    - (id)initWithContentRect:(NSRect)contentRect styleMask:(unsigned int)aStyle backing:(NSBackingStoreType)bufferingType defer:(BOOL)flag
    {
    	self = [super initWithContentRect:contentRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:YES];
    	return self;
    }
    
    In the .nib file I added a Window with a textfield and made all of the connections. When I run the app the window is drawn without a title bar but you can't edit or click on the text field... Anyone have any idea why?
     
  2. HiRez macrumors 603

    HiRez

    Joined:
    Jan 6, 2004
    Location:
    Western US
    #2
    You might need to tell your window subclass to use the text field as the initial first responder:
    Code:
    [myWindow setInitialFirstResponder:myTextField];
    Dunno, just guessing really...
     
  3. crees! macrumors 68000

    crees!

    Joined:
    Jun 14, 2003
    Location:
    MD/VA/DC
    #3
    Okay. I'm just starting out here with Objective-C and from reading up last night what you're doing at the moment is redundant in initWithContentRect. If initWithContentRect is a function in NSWindow then just call it directly and do not override the function like you have done.
     
  4. Eraserhead macrumors G4

    Eraserhead

    Joined:
    Nov 3, 2005
    Location:
    UK
    #4
    Why are you creating an NSWindow subclass? I've never done so myself...
     
  5. CaptainZap thread starter macrumors regular

    Joined:
    Jan 17, 2007
    #5
    Becuz i r bad prgrammer =D. But really I was just messing around and was trying to make a window without a titlebar. Anyone know a better way to accomplish this?

    But I'm calling the super function of it... It works. I'm just trying to figure out the textfield...

    Look, I'm not that crazy xD http://developer.apple.com/samplecode/RoundTransparentWindow/listing6.html
    And that even answered my question, all I needed to add was this code to my subclass
    Code:
    - (BOOL) canBecomeKeyWindow
    {
        return YES;
    }
     
  6. crees! macrumors 68000

    crees!

    Joined:
    Jun 14, 2003
    Location:
    MD/VA/DC
    #6
    True, it does work. But since you're not doing anything else or special in that function it's not needed because your class inherited it from NSWindow.
     

Share This Page