Announcement

Collapse
No announcement yet.

Some Cocoa/XCode help

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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
    My pathetic worklog.
    CarFrontEnd (now it's own sub-forum!!!!)

    Comment


    • #3
      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.

      Comment


      • #4
        Um... why not just create your own BorderlessWindow class and set a window in IB to have that as its custom class?

        Comment


        • #5
          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
          My pathetic worklog.
          CarFrontEnd (now it's own sub-forum!!!!)

          Comment


          • #6
            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:.

            Comment


            • #7
              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.

              Comment


              • #8
                Thank you all for your suggestions. Jirkaís three lines worked just perfect for me. Itís working now.

                Comment

                Working...
                X