Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What UIView is returned when using -viewWithTag: when several views have same .tag?

Tags:

iphone

uiview

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
like image 776
willc2 Avatar asked Dec 30 '09 06:12

willc2


2 Answers

If you use Interface Builder, it depends which order you use. In my case, UIActivityIndicator will be my result, and not UIWebView or UIButton with the same tag.

IB Layout

like image 26
Jasper Avatar answered Sep 23 '22 02:09

Jasper


Its weird 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.

like image 168
Madhup Singh Yadav Avatar answered Sep 23 '22 02:09

Madhup Singh Yadav