Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView viewWithTag 0 problem

Tags:

iphone

sdk

uiview

On view in IB I have numerous items (including view itself). ONLY one item has tag 0, yet following line works for ANY UITextBox other then the one with tag 0. Note that only ONE UITextBox has tag 0, why:

(UITextField *) [self.view  viewWithTag:0]).text = @"foo";

Interesting that when triggered event received for the element with tag 0, I can get value of Tag 0 with no problem.

Is there a limitation to look for tag 0 elements?

like image 394
leon Avatar asked Oct 08 '09 19:10

leon


3 Answers

All views have a 0 tag as a default so if you get a 0 view it could be any view. For it to work you need to use non-zero values that you set in your program or within Interface builder.

like image 104
Boiler Bill Avatar answered Oct 08 '22 06:10

Boiler Bill


actually, if you ask a view called "X" for a viewwithtag 'zero', you will probably get the "X" view as the return value :/ idiotic behaviour. send regards to apple

like image 44
que Avatar answered Oct 08 '22 04:10

que


que is right. I just got bit by this.

From the docs:

Discussion This method searches the current view and all of its subviews for the specified view.

At least it's documented correctly. I guess we need a method called "subviewWithTag:"

like image 30
Paul Bruneau Avatar answered Oct 08 '22 04:10

Paul Bruneau