• 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 Custom Views in Interface Builder
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Creating Custom Views in Interface Builder


  • Subject: Re: Creating Custom Views in Interface Builder
  • From: Michael Fey <email@hidden>
  • Date: Tue, 18 Mar 2008 19:44:46 -0400

Sorry for the long delay in replaying, I wanted to make sure that what I was doing was going to work before I responded. It turns out that Jacob was the closest to the solution that I wanted (though I thank everyone for their suggestions). The one common theme in the suggestions involved overriding drawRect to accomplish laying out my component. My intention was to use IB to layout my component and not have to worry about drawRect at all.

What I ended up with is a class called ProgressViewController that has an IBOutlet NSView* progressView; Within a separate nib I made the File's Owner be of type ProgressViewController and laid out my view. Then I simply connected my view to the File's Owner progressView outlet. Lastly, in ProgressViewController'sinit method I just (as Jacob suggested) load the nib that contains my progress view:
- (id) init {
if (![super init])
return nil;

if (progressView == nil) {
if (![NSBundle loadNibNamed:@"ProgressView" owner:self])
NSLog(@"Failed to load ProgressView");
if (progressView == nil)
NSLog(@"progressView is still nil");
}
return self;
}



Now whenever I want to create a new view I just create a new ProgressViewController instance and use its getter method (- (NSView*) view;) to access my custom view and add it where I need it.


Thanks again!

Warm regards,
	Michael


On Mar 14, 2008, at 2:43 PM, Jacob Lukas wrote:

Whoops meant to hit "Reply All"

On Mar 14, 2008, at 14:33, Michael Fey wrote:

Hello List!

I am trying to create a custom view class using Interface Builder that I can then instantiate within my code as many times as needed. In this particular case I have a control that I've created that contains a progress bar, two text fields, two buttons, and an image view. I then want to be able to create any number of these components within my source code and add them to another view dynamically.

I'm guessing that this question has been answered before, but my searches have been unsuccessful. If someone could point me in the right direction, that would be a great help. Thanks!

Regards,
	Michael

What about creating this view in a separate nib, and loading it each time you wish to insert it somewhere? Perhaps using +[NSBundle loadNibNamed:owner:]


-Jacob

_______________________________________________

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

_______________________________________________

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


References: 
 >Re: Creating Custom Views in Interface Builder (From: Jacob Lukas <email@hidden>)

  • Prev by Date: Re: Cocoa-dev Digest, Vol 5, Issue 432
  • Next by Date: CGFloat in 10.4
  • Previous by thread: Re: Creating Custom Views in Interface Builder
  • Next by thread: Custom NSCell selection and click issues
  • Index(es):
    • Date
    • Thread