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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T10:00:14+00:00 2026-05-30T10:00:14+00:00

My program adds an indefinite amount of views to the screen (determined by the

  • 0

My program adds an indefinite amount of views to the screen (determined by the user at runtime), and I keep track of these views by storing them in an array.

Inside my view controller

for (NSString *equationText in equationData) {

// creates a FormulaLabel object for every object in the equationData mutable array 

FormulaLabel *tempLabel = [[FormulaLabel alloc] initWithFrame:CGRectMake(frame)];
[view addSubview:tempLabel];
[balanceItems addObject:tempLabel];  //balance items keeps track of all the views

When I update my data, I need a different arrangement of views on the screen, so I figured the quickest way to reflect a data change would be to remove all the views currently on the screen and add new views from the updated data.

For this approach, (as far as I know) I need to remove the views from superview, release them, and remove the objects stored in balanceItems. Then I need to init the new views, add them to the subview, and add them to the array. However, the code below generates an error.

for (UIView *view in balanceItems) {

    [view removeFromSuperview];
    [view release];
}

[balanceItems removeAllObjects];

What is the proper way to remove the views from the superview as well as the array?

  • 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-30T10:00:15+00:00Added an answer on May 30, 2026 at 10:00 am

    First, you should release the views correctly when creating them:

    FormulaLabel *tempLabel = [[FormulaLabel alloc] initWithFrame:CGRectMake(frame)]; // retain count is 1
    [view addSubview:tempLabel]; // retain count is 2
    [balanceItems addObject:tempLabel]; // retain count is 3
    [tempLabel relase]; // retain count is 2
    

    You should release tempLabel because you obtained it with an init method, so you own it.

    Then when you remove the views; you don’t have to call release:

    for (UIView *view in balanceItems) {
        [view removeFromSuperview]; // retain count is 1
    }
    [balanceItems removeAllObjects]; // retain count is 0 => view gets deallocated
    

    because the view is currently retained only but the super view and the array, so it will be deallocated when you remove it from them.

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

Sidebar

Related Questions

I'm currently building a program which adds to the current user's shell depending on
Does using this pointer adds another operation to the program at runtime? Just to
In my program it adds a shortcut to the screen. I get the icon
I have a program in which the user adds multiple objects to a scene.
I need to make a program that adds long integers without using the biginteger
I am currently creating a program that dynamically adds Image to a dockPanel every
I have a program that encrypts files, but adds the extension .safe to the
This program adds two matrices but it's giving too many errors and I can't
I have a program that adds LineItems to a ZedGraph pane whenever data parameters
Every time my program runs vs adds the default configuration to my app.config file.

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.