Results 1 to 8 of 8

Thread: Some Cocoa/XCode help

  1. #1
    Constant Bitrate
    Join Date
    Dec 2005
    Location
    London, UK
    Posts
    182

    Some Cocoa/XCode help

    Hi guys,

    I know this not the right place to ask this type of questions but I didn’t find any better place either. Sorry for that.

    I’m having some trouble using NStextField with NSView - when I run the programme the text box becomes inactive. But the same programme if I create using NSWindow (in stead of NSView) it works fine. I created a NSView sub-class in XCode, drag the .h file to IB, instantiate the class and put a NSTextField in there. I'm creating the window the programmatically. Am I doing any thing wrong?

    Thanks a lot in advance!!!

  2. #2
    CarFrontEnd Creator iamgnat's Avatar
    Join Date
    Jul 2004
    Location
    NoVA
    Posts
    867
    I think i'm a bit confused. Are you creating the View/Window dynamically and then adding TextFields?

    If your Window and it's objects are static, then why aren't you using a NIB and linking to the objects that way?

    If you are trying to do it dynamically, then I have no idea Try the cocoa-dev list and see if you can find anything there.

    -dave

  3. #3
    Constant Bitrate
    Join Date
    Dec 2005
    Location
    London, UK
    Posts
    182
    Sorry, I wasnít that clear. Iím trying to explainÖÖ

    Iím using borderless window for my app and only the borderless window Iím drawing dynamically but not any other controls. So, say, AppController is a subclass of NSObject, so I have:

    #AppController.h
    Code:
    #import <Cocoa/Cocoa.h>
    
    @interface AppController : NSObject
    {
        IBOutlet NSView *aView;
        NSWindow *aWindow;
    }
    @end
    and then in the AppController.m
    Code:
    #import "AppController.h"
    
    @implementation AppController
    
    - (id)awakeFromNib {
    	
    	aWindow =[[NSWindow alloc] initWithContentRect:NSMakeRec(150,30,500,361)
    	  styleMask:NSBorderlessWindowMask|NSTexturedBackgroundWindowMask 
    	  backing:NSBackingStoreBuffered 
    		defer:NO];
    	
    	[aWindow setContentView:aView];
    	[aWindow makeKeyAndOrderFront:nil];
    	[NSMenu setMenuBarVisible:NO];
    	
    	return aWindow;
    }
    @end
    And then using the NIB Iím adding the textFiled to the NSView (aView). Am I clear now? Befor posting it here I tried several cocoa-dev list/forum but didnít get anything helpful.

  4. #4
    Low Bitrate
    Join Date
    Jul 2005
    Location
    Atlanta
    Posts
    68
    Um... why not just create your own BorderlessWindow class and set a window in IB to have that as its custom class?

  5. #5
    CarFrontEnd Creator iamgnat's Avatar
    Join Date
    Jul 2004
    Location
    NoVA
    Posts
    867
    Quote Originally Posted by Mahalis
    Um... why not just create your own BorderlessWindow class and set a window in IB to have that as its custom class?
    Or use a normal window and change it's attributes in the awake from nib method (and default it's visable setting to off so that the user doesn't see the changes happening).

    -dave

  6. #6
    Low Bitrate
    Join Date
    Jul 2005
    Location
    Atlanta
    Posts
    68
    You can't set a window's style mask after it's been created. The only way to get a borderless window is to create a new one in code - which is, as far as I can tell, the problem here - or to subclass it and override initWithContentRect:.

  7. #7
    QCar Creator Jirka Jirout's Avatar
    Join Date
    Jul 2005
    Location
    Netherlands
    Posts
    590
    Borderless window does not accept key window status by default, so NSTextField or other keyboard-controlled widget will not work there.

    You have to sub-class the NSWindow:

    Code:
    @interface MyWindow:NSWindow{}
    @end
    
    @implementation MyWindow
     -(BOOL) canBecomeKeyWindow{
      return YES;
     }
    @end
    Then you can replace NSWindow with MyWindow in the code you quoted above and your borderless window will accept key events the same way as a regular window.

  8. #8
    Constant Bitrate
    Join Date
    Dec 2005
    Location
    London, UK
    Posts
    182
    Thank you all for your suggestions. Jirkaís three lines worked just perfect for me. Itís working now.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •