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

  • SEARCH
  • Home
  • 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 3241598
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T18:13:02+00:00 2026-05-17T18:13:02+00:00

I am trying to create a custom view and load it into a window.

  • 0

I am trying to create a custom view and load it into a window.

In the end, I know there will be a few steps to follow, reflecting the key relationships that I am missing. I am hoping someone can explain, in a series of steps, how one creates a view object, view controller, associated .xib, and then loads it into a window (after clearing the current view).

And I mean the real nitty gritty of where to declare and initialize, what needs to be imported, everything. Because I am looking through every book I have and it is just not clear to my puny brain.

Thanks!

  • 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-05-17T18:13:03+00:00Added an answer on May 17, 2026 at 6:13 pm

    how one creates a view object, view controller, associated .xib, and then loads it into a window …

    These are several things, and some of them conflict.

    If you create a view in code, you don’t need to (and shouldn’t) also create it in a nib, and vice versa.

    If you create a view controller to load the nib, you will be creating the view in a nib, so you definitely should not create the same view in code.

    You do not need to create a view controller for most views. It is more common to have each controller own the entirety of exactly one window. The only time you need view controllers is when you manage a complex view hierarchy in a single window (most likely if you make your application single-window).

    … (after clearing the current view).

    There is no “current view” in Cocoa. You can have multiple windows, and each has a deep view hierarchy that you usually don’t edit at run time. Swapping one view for another outside of some sort of tabbed UI is very unusual.

    Creating a view object in code

    Send the desired view class an alloc message and the returned view an initWithFrame: message (unless otherwise prescribed by the class’s documentation). You will, of course, need to release or autorelease this view.

    Creating a view object in a nib

    Giving it its own nib (especially for view controllers)

    Use the view-nib template in IB (New) or Xcode (Add File). If you create it in Xcode, don’t forget to get info on it and make it localizable. If you create it in IB, you should save it into one of your .lproj folders; then it will already be localizable.

    A nib created from those templates will contain one empty NSView. You can change its class and/or add subviews as described below.

    Making it in an existing nib

    Drag “Custom View” from the Library palette into the nib window, then set the view’s class on the ⌘6 inspector.

    You only do this for the top-level view in the nib. For its subviews, see below.

    Putting the view into a window’s view hierarchy

    If the view should be the root of the window’s view hierarchy (the window’s content view)

    Set the window’s content view.

    In IB, you can’t change the window’s content view. Instead, you change things about it—its class, subviews, etc. There is no reason to try to replace the window’s content view with another view in IB.

    If the view should be a subview of an existing view

    The way to do this in code is to send the superview an addSubview: message.

    If both views are in the same nib, create the subview and add it to the superview in the same act. Drag “Custom View” from the Library into the superview, not the nib window, then set the subview’s class on the ⌘6 inspector.

    (If you’re customizing one of the standard Apple views, rather than making a completely original custom view, drag the standard Apple view you based yours on from the Library, then change its class to your customized subclass.)

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

Sidebar

Related Questions

I am trying to load a html page through UIWebview.I need to disable all
I'm trying to build a C++ extension for python using swig. I've followed the
I'm trying to write test harness for part of my Android mapping application. I
I'm trying to build a Chrome browser extension, that should enhance the way the
I am trying to redirect to a specific path based on HTTP_HOST or SERVER_NAME
I am trying to understand the practical difference during the execution of a program
I am playing with TFS 2010, and am trying to setup a build process
I have several USB mass storage flash drives connected to a Ubuntu Linux computer

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.