Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8790643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:42:38+00:00 2026-06-13T22:42:38+00:00

In IB, put 2 custom views into one window. I don’t see any way

  • 0

In IB, put 2 custom views into one window. I don’t see any way to give them separate names. In Inspector-Info I had to use the same name, the class name, for both of them in the drop-down menu. I tried

DrawRect:  NSRect bounds = [self bounds];       
[[NSColor greenColor] set]; 
[NSBezierPath fillRect:bounds];

which filled both custom views with green. But I would like to fill, draw, etc. independently in each custom view. How can I address each view separately? Multiple custom views, later. Or does Cocoa require only one view per class?

This is probably trivial, but Google and the similar questions list here didn’t come up with anything close. There’s a lot of about multiple view controllers, but I don’t need to switch views.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T22:42:39+00:00Added an answer on June 13, 2026 at 10:42 pm

    IB will show you the names of the classes that you can assign to an object. If you have only one custom class (eg. “myCustomClass”) then it will only show that one in the drop-down menu.

    I think the best solution to your problem, if you want tu use only one class, is to put the drawing code in two separate functions and assign each view an IBOutlet, then call the function from the controller class.

    //Add this to your interface
    NSNumber *myColor;
    
    //Add/Edit the following functions
    - (void)drawRect:(NSRect)aRect
    {
        //Some code...
        if ([myColor intValue]) [self drawGreen];
        else [self drawRed];
        //Some code...
    }
    
    - (void)drawGreen
    {
        NSRect bounds = [self bounds];       
        [[NSColor greenColor] set]; 
        [NSBezierPath fillRect:bounds];
    }
    
    - (void)drawRed
    {
        NSRect bounds = [self bounds];       
        [[NSColor redColor] set]; 
        [NSBezierPath fillRect:bounds];
    }
    
    - (void)drawRedOrGreen:(int)aColor
    {
        myColor = [NSNumber numberWithInt:aColor];
    }
    

    You have to add the following two lines to your controller’s interface

        IBOutlet myCustomClass *customView1;
        IBOutlet myCustomClass *customView2;
    

    And you have to set each view’s color.
    This will set it when it loads for the first time.

    - (void)awakeFromNib
    {
        [customView1 drawRedOrGreen:1]; //Green
        [customView2 drawRedOrGreen:0]; //Red
    }
    

    This way each view will be coloured differently.

    An alternative solution would be to create two separate custom classes (eg. “myCustomClass1” and “myCustomClass2”) which would have their own drawing code…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Hello, I want to put custom status bar in notification window of iphone. is
I'm trying to put some custom list adapters into their own classes to make
I need create custom dialog and put JPanel into it. Is it possible?
I've got some custom metadata to put into a PNG file. It's being saved
I've made a custom control, it's a FlowLayoutPanel, into which I put a bunch
I need to put it some custom logic into my iPhone app so that
I need to put a custom hover menu from http://www.addthis.com/help/toolbox , but Rails uses
Im trying to use Nets/HTTP to use POST and put in a custom user
I want to create a custom navigation bar to put in my header.phtml file.
I am creating an actionbar with custom looking buttons that I put in the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.