Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

kwfl

macrumors 6502
Original poster
Aug 20, 2007
403
0
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.
 
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:

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.
 
So what i am asking cant be done or i have asked for a stupid thing that nobody is interested to answer?
 
So what i am asking cant be done or i have asked for a stupid thing that nobody is interested to answer?

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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.