UIView viewWithTag 0 problem

2019-01-15 16:13发布

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?

4条回答
我欲成王,谁敢阻挡
2楼-- · 2019-01-15 16:58

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:"

查看更多
Lonely孤独者°
3楼-- · 2019-01-15 17:04

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

查看更多
一纸荒年 Trace。
4楼-- · 2019-01-15 17:04

set self tag as -1. won't affect other view's tag.

查看更多
登录 后发表回答