Ios,viewwithtag Search Mechanism

Source: Internet
Author: User

I haven't written anything for a long time. Don't say much nonsense.

Official start

There are many ways to get a reference to a desired view in iOS, one of which is to use Viewwithtag: (Nsinteger) and fill in the tag to get the tag.

When we see the method, we naturally think that this tag is something like UUID, different view writes different tag, then the corresponding view is obtained by tag.

But tag is our own manually added, if there are two view of the same tag, we get through the Viewwithtag view is which view it?

To get an answer, I didn't really want to go through the document, and I thought it was a good test.

(because in this hair map, audit too troublesome, I will not send (or lazy))

Create a new project, open IB, and drag into a few view hierarchies like this:

View (Self.view)

--view1

----VIEW11

----VIEW12

--view2

----VIEW21

Each view sets a different background color (not set black), sets a different tag (my tag is 200, and then adds a number) after the code:

UIView *viewtext = [Self.view viewwithtag:2001];

Viewtext.backgroundcolor = [Uicolor blackcolor];

See which view turns black.
Testing process1.view1 for 2001,view2 is 2001, find 2001, find View1.2.view1 for 2001,VIEW11 is 2001, find 2001, find View1.3.VIEW11 for 2001,view2 for 2001, find 2001, find VIEW114.VIEW11 for 2001,VIEW21 2001, find 2001, find VIEW11 I feel the way to find is very simple, is through the view hierarchy search, from the beginning of the first add to find, and then return. Simply said above I draw the hierarchy structure, from top to bottom there are 5 view, find the way is from the top to the bottom of the search, found on the return.
Written in the last pure personal assumption, no official support, if there is wrong place, please correct me.

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Ios,viewwithtag Search Mechanism

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.