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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T09:18:58+00:00 2026-05-26T09:18:58+00:00

This is not a real problem, i want just a clarification. I’m adding some

  • 0

This is not a real problem, i want just a clarification.
I’m adding some subviews on a UIButton(each button has a tag), i know that there may be either 4 or 5 subviews.
So, when i want to remove some subviews(specifically the 4th and 5th in this case):

int cnt=[[(UIView *)[self.scrollView viewWithTag:index] subviews] count];
  if (cnt==4) {
      [[[(UIView *)[self.scrollView viewWithTag:index] subviews] objectAtIndex:3] removeFromSuperview];
  }
  if (cnt==5) {
      [[[(UIView *)[self.scrollView viewWithTag:index] subviews] objectAtIndex:3] removeFromSuperview];
    //[[[(UIView *)[self.scrollView viewWithTag:index] subviews] objectAtIndex:4] removeFromSuperview]; <-- this crash
      [[[(UIView *)[self.scrollView viewWithTag:index] subviews] objectAtIndex:3] removeFromSuperview];

    }

The commented line can not be executed, of course, because there aren’t more 5, but 4 subviews.
So I have to remove the view pointing twice on the same index.
I would like to know if it’s a safe way to remove them, and i want to be sure that the last view is moved one position lower in the array [[self.scrollView viewWithTag:index] subviews].

Hope it is clear.
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-26T09:18:59+00:00Added an answer on May 26, 2026 at 9:18 am

    I’d rather use something like this:

    for(int i=cnt-1;i>=3;i--)
    {
      [[[(UIView *)[self.scrollView viewWithTag:index] subviews] objectAtIndex:i] removeFromSuperview];
    }
    

    Usually, when removing objects from lists, the safest method is to begin at the end. This way it doesn’t even matter if they get reorganized.

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

Sidebar

Related Questions

Note: this is not real information: $ ssh-keygen -t rsa -C "tekkub@gmail.com" Generating public/private
This is not a real bug BUT for sure it is not what you
If this is not a real question then feel free to close ;)
Sorry for this not being a real question, but Sometime back i remember seeing
I know this is not a real programming question. But, it relates to programming
Update: This issue was not properly explored. The real issue lies within render :json
I have a simple, real life problem I want to solve using an OO
I ask this not to start anything negative. Rather, after looking at ASP.NET MVC
why is this not ok? aContract = function(){}; aContract.prototype = { someFunction: function() {
Why does this not work? Do I not understand delegate covariance correctly? public delegate

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.