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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T15:40:31+00:00 2026-06-10T15:40:31+00:00

Because right now, viewWithTag actually search for itself first, and then all subviews recursively

  • 0

Because right now, viewWithTag actually search for itself first, and then all subviews recursively down the whole subtree, for a view with that tag.

But what if I set the tags of the subviews to 100, 101, etc, and later on, look for tag 100, but the parent of this current view sets the current view’s tag to 100? Then viewWithTag will return the current view instead of any subview.

It is also strange that if the code is

[fooView viewWithTag: 123]

why would the code want to search the subtree including fooView itself? It is like, the code doesn’t know fooView good enough to want to search for it too. Or put it another way, fooView is told to search itself… which is strange. A view doesn’t know itself? (need to do a search to look for itself?)

So is there a way to search for subviews and grand-subviews only (without searching for self)?

  • 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-06-10T15:40:33+00:00Added an answer on June 10, 2026 at 3:40 pm

    Take advantage of the recursive nature of -viewWithTag:

    - (UIView *)viewWithTagNotCountingSelf:(NSInteger)tag
    {
        UIView *toReturn = nil;
    
        for (UIView *subView in self.subviews) {
            toReturn = [subView viewWithTag:tag];
    
            if (toReturn) {
                break;
            }
        }
        return toReturn;
    }
    

    Edit: this will drill down farther than “grand-subviews”: it will get any view within the hierarchy that is not self. Also this is to be implemented in a category on UIView.

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

Sidebar

Related Questions

Right now, I'm extremely frustrated because I was in the process of developing some
Can any one differentiate Fragments and shared preferences on android. Because, Right now i
The reason I'm asking this is because right now I use an NSMutableSet of
The title pretty much describes my entire question. Because right now I'm wondering if
I want to add horizontal scrollbars to my JScrollPane, because my table right now
I want to set background image to right and top of my span because
I feel silly asking this because I'm betting the answer is staring right at
I'm not sure StackOverflow is the right place to ask this question, because this
Ok, guys, I think that's the right place to ask a question, because it's
Because data from file look like this: line 1 is name (first last), next

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.