Cannot add NSView as a subView to content view

Discussion in 'Mac Programming' started by kwfl, Apr 10, 2010.

  1. kwfl macrumors 6502

    Joined:
    Aug 20, 2007
    #1
    Hi there,

    i have been trying for a while now to do either of two things wtih no luck.

    1- create an nsview programmatically and add it as a subview to a current content view like this

    Code:
    NSView *view = [[NSView alloc] initWithFrame: NSMakeRect(0, 0, 100, 100)];
    [[window contentView] addSubview: view];
    i recieve this error, [NSView addSubview:] unrecognised selector sent to object 0x109x04 (whatever)

    2-

    add a subview to a current view using a CustomNSWindowController and a sepparate xib (nib) file. The nib file has a an additional (other than the one in the window item) custom view that has a connected outlet in the CustomNSWindowController interface and impelentation.

    Code:
    @interface CustomNSWindowController: NSWindowController
    {
    IBOutlet NSView *customView;
    }
    
    @end
    the custom NSWindowController works very well when i want a separate window out of it by calling the window method like this

    Code:
    CustomNSWindowController *controller = [[CustomNSWindowController alloc] initWithNibName: @"myNib"];
    
    [controller window] pops up that window beautifully
    however, if i try to add the customView as a subview of the current content view it does not work (basically i have the customView as nil

    Code:
    [[window contentview] addSubview: [controller customView]];
    customView is always nil.


    i would appreciate any help in anyone of these two methods.
     
  2. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #2
    You need to be more careful with the method name. You can't just capitalise it any old way you like. It's addSubview: not addSubView:
     
  3. kwfl thread starter macrumors 6502

    Joined:
    Aug 20, 2007
    #3
    Thanks for the heads up, but i wrote these lines of code in this composer window (not copied from xcode) for demonstration. I am sure the code in xcode is perfect as it builds, links with no errors or warnings.

    i have fixed the addSubview method.
     
  4. kwfl thread starter macrumors 6502

    Joined:
    Aug 20, 2007
    #4
    So what i am asking cant be done or i have asked for a stupid thing that nobody is interested to answer?
     
  5. robbieduncan Moderator emeritus

    robbieduncan

    Joined:
    Jul 24, 2002
    Location:
    London
    #5
    1) Thread bumps are against the rules

    2) You have not posted the actual code (copy and paste it from XCode) so we are all just guessing. There was an obvious massive error in the code you posted. But as you had not copied and pasted it I was just wasting my time reading it.
     

Share This Page