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 7026887
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T00:10:35+00:00 2026-05-28T00:10:35+00:00

I have a custom view to which I need to add a couple of

  • 0

I have a custom view to which I need to add a couple of subviews programmatically. Which is the best place to create and add these subviews? Apple docs say:

If your view class manages one or more integral subviews, do the following: Create those subviews during your view’s initialization sequence.

This is a bit unclear to me. Should I handle that in initWithFrame, initWithCoder or somewhere else?

Note that I’m not talking about controllers here, this is a View that needs to initialize itself.

  • 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-28T00:10:35+00:00Added an answer on May 28, 2026 at 12:10 am

    initWithFrame is the method you call to create a UIView programmatically, while initWithCoder is called when a UIView is instanciated from a XIB.

    So it all depends on how you’re going to create your containing view.
    A way to cover all cases :

    - (id) initWithFrame:(CGRect)frame
    {
        if ((self = [super initWithFrame:frame])){
             [self setUpSubViews];
        }
        return self;
    }
    
    - (id) initWithCoder:(NSCoder*)aDecoder 
    {
        if ((self = [super initWithCoder:aDecoder])){
             [self setUpSubViews];//same setupv for both Methods
        }
        return self;
    }
    
    - (void) setUpSubViews
    {
         //here create your subviews hierarchy
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my custom View which I have added to my viewControllers's view, I need
I have view on which I defined a custom tagName. I need to be
I have a view with two subviews: A UIImageView A small Custom View which
I have a custom view which has a piano keyboard drawn inside of it.
Please help me to turn off user interaction. I have a custom view which
I have two helper methods inside a custom View which are called by their
I have a custom view with several NSTextField controls for which I want to
I have a GridView in which each row has a custom view. The grid
I have a custom component which consists of 2 text view and 4 toggle
I have a CCLayer which I need to add a camera to, on top

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.