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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:43:14+00:00 2026-05-15T22:43:14+00:00

i have a view that addes a subview programmtically SelectionScreenTable *aSelectionScreenTableViewController = [[SelectionScreenTable alloc]

  • 0

i have a view that addes a subview programmtically

    SelectionScreenTable *aSelectionScreenTableViewController = [[SelectionScreenTable alloc] initWithNibName:@"SelectionScreenTable" bundle:[NSBundle mainBundle]];

aSelectionScreenTableViewController.view.bounds = CGRectMake(0,0,955,520);
aSelectionScreenTableViewController.view.center = CGPointMake(528, 379);

[self.view addSubview:aSelectionScreenTableViewController.view];

Now i wish to remove it on clicked on a button and add it again so i did it wrote another 1 like this

SelectionScreenTable *viewController =[[SelectionScreenTable alloc]initWithNibName:@"SelectionScreenTable" bundle:nil];
viewController.view.bounds = CGRectMake(0,0,955,520);
viewController.view.center = CGPointMake(528, 379);

UIView *CV = [UIView alloc];
CV = [[self.view subviews]objectAtIndex:3]; 
[CV removeFromSuperview];
[CV release];

[self.view addSubview:viewController.view];

it Works but one thing i noticed was when it was removed and added on again. the

[self.view subviews]objectAtIndex:3 seems to change indexes? Because i can only click a certain number of times before the app crashes.

If so, should i do a increment where a variable + 1 everytime the button is clicked and use objectAtIndex:variable?

  • 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-15T22:43:15+00:00Added an answer on May 15, 2026 at 10:43 pm

    Using the indexes seems like it’ll be fragile in the long run, so is probably best avoided.

    One approach would be to retain the pointer to the view in a member variable so you don’t need to use objectAtIndex.

    Another approach would be to do:

    [CV setTag:5];
    

    and instead of objectAtIndex, use:

    [self.view withWithTag:5];
    

    (‘5’ is an arbitary choice – it should be a unique number within your program! It would be best to use a #define or enum to store the value – eg. #define MY_VIEW_TAG 5 and setTag:MY_VIEW_TAG etc)

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

Sidebar

Related Questions

I have a UIView that gets added to my UITableView .view as a subview.
I have a view that is added as a subview in a viewcontroller. The
I have an activity view that I have added in AppDelegate class to tap
I am beginner in rails. I have view that i try to print inside
I have a view that has a column to make it sortable. When clicking
I have a view that renders a list elements using the following template :
I have a view that shows user profile fields in a tabular format. There
I have a view that is used in a UINavigationController and and is automatically
I have a View that is basically setup like this: <Grid> <ViewBox> <Grid> <ItemsControl
I have a View that contains a ParentModel, which contains 2 Models. I only

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.