tags:

views:

292

answers:

2

Say I have 4 UIViews, made in IB, all with the tag property = 2

When I get a view with:

 UIView *thisView = (UIView*)[self.view viewWithTag:2];

What is the criterion for retrieving that UIView since several have the same .tag value?

Is it:

  • random
  • the first one created
  • the view with the lowest index in it's superview
  • something else
A: 

if I had to guess, I would assume that it would be almost-random. as in, you'll probably get some amount of consistency, but every so often it'll be something completely different (heh).

I'd say use different tags for them?

Oren Mazor
+1  A: 

Its weard but the view that is added first will be returned if you try to get the views among the views with same tag. You can check it in this way too.

NSLog(@"%@",[[self.view viewWithTag:custTag] class]);

Hope this helps.

Madhup