Re: addsubview
Re: addsubview
- Subject: Re: addsubview
- From: Graham Cox <email@hidden>
- Date: Wed, 25 Apr 2012 09:53:15 +1000
On 21/04/2012, at 2:49 AM, koko wrote:
> Ah, ain't Cocoa a great, modern (85?) environment.
Don't blame the framework for your own incompetence.
> But I never see thev iew!
>
> - (void)makeAndWrapViews
> {
> NSRect frame = [self frame];
> frame.size.width = 288;
> frame.size.height = 259;
>
> m_text = [[NSPDText alloc] initWithFrame:frame];
>
> BOOL text = [NSBundle loadNibNamed:@"NSPDText" owner:m_text];
>
> if (text)
> {
> [self addSubview:m_text];
> }
> }
The code you posted is pretty bizarre. It might work, but there's certainly not enough to go on for others to help you.
What is NSPDText? Is that a class of your own (if so, it should NOT be prefixed 'NS', that's Apple's reserved prefix. If it's supposed to be a Cocoa class, I have never heard of it). Using a view as 'Files Owner' for a NIB is very unusual and unconventional. It might work, but then again, it might not - it's not standard practice, so there won't be a large body of code to compare it with.
Have you tried simply instantiating NSPDText in a window and seeing whether it in fact does draw anything? Perhaps the reason nothing appears is because that class is broken.
What is the reason for not simply adding your view to the tab view in IB? Again, that's what I and probably most Cocoa programmers would do.
The problem you seem to have (not just here, but in most of the cries for help you post) is that you don't take the time or trouble to learn how things are typically done, but half-understand it and then write a screed of code based on that improperly understood concept. You also then ignore advice to go back and do it properly and persist in doing it your (incorrect) way. For example, using the NSBundle method above is rarely done. Instead, you conventionally use a higher level class such as NSVIewController or NSWindowController that loads the nib for you. I'm not saying it's wrong, but it is unusual, and it's certainly symptomatic of an approach that will lead to buggy, difficult to maintain code that others will have little chance of helping you with, because it's "out there" in uncharted territory.
There is a very strong streak of the bad workman blaming his tools here.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden