• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Creating a NSScrollView programmatically
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating a NSScrollView programmatically


  • Subject: Re: Creating a NSScrollView programmatically
  • From: publiclook <email@hidden>
  • Date: Mon, 27 Oct 2003 13:39:52 -0500

The designated initializer for most views (including NSScrollView) is -initWithFrame:. If you only call -init, I expect you get a view with no frame and therefore no size. I recommend reading the introductory information on Objective-C and Cocoa at Apple's site:

See designated initializer at http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/ 4objc_runtime_overview/chapter_4_section_2.html

http://developer.apple.com/documentation/Cocoa/Conceptual/ CodingGuidelines/Articles/FrameworkImpl.html

And from Apple's NSView documentation:

- (id)initWithFrame:(NSRect)frameRect

Initializes a newly allocated NSView with frameRect as its frame rectangle. The new view object must be inserted into the view hierarchy of an NSWindow before it can be used. This method is the designated initializer for the NSView class. Returns self.

Other problems Arthur VIGAN might have:

If mainWindow in nil or is not an NSWindow instance, his code won't work.
If the window is not yet initialized, it may not have a valid bounds at the time [windowContentView bounds] is called.


On Monday, October 27, 2003, at 12:35 PM, Dusan Vujosevic wrote:

I asked almost the exact same question last week and got no response. I ended up making a custom view (with all the rest of controls inside it) in IB an unarchiving and creating instances of the view as I needed. That view (from the NIB) does appear in the window just fine so I am guessing we are missing something when we create them programatically...

Dusan

P.S. If you need help with the view in a NIB let me know.

On 27-Oct-03, at 6:23 AM, Arthur VIGAN wrote:

Hi,

I am trying to create an NSScrollView programmatically in the content view of a window. I have the following code, but it doesn't work (scrollView and mainWindow are defined in the header file):

- (IBAction)createScrollView:(id)sender
{
NSView *windowContentView = [mainWindow contentView];
NSRect windowContentBounds = [windowContentView bounds];

scrollView = [[NSScrollView alloc] init];

[scrollView setBorderType:NSNoBorder];
[scrollView setHasVerticalScroller:YES];
[scrollView setBounds: windowContentBounds];

[windowContentView addSubview:scrollView];
}

When my window appears, it is just empty. Can anybody help?

-- Arthur
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: Creating a NSScrollView programmatically (From: Dusan Vujosevic <email@hidden>)

  • Prev by Date: Re: Smaller Application?
  • Next by Date: Re: EOF on Mac OS X
  • Previous by thread: Re: Creating a NSScrollView programmatically
  • Next by thread: Re: Creating a NSScrollView programmatically
  • Index(es):
    • Date
    • Thread