本文介绍了UIView viewWithTag 0 问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 IB 中查看我有很多项目(包括查看本身).只有一个项目有标签 0,但以下行适用于任何 UITextBox,而不是带有标签 0 的项目.请注意,只有一个 UITextBox 有标签 0,为什么:

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

有趣的是,当接收到标记为 0 的元素的触发事件时,我可以毫无问题地获取标记 0 的值.

查找标签 0 元素是否有限制?

解决方案

所有视图默认都有一个 0 标签,所以如果你得到一个 0 视图,它可以是任何视图.要使其正常工作,您需要使用您在程序或界面构建器中设置的非零值.

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?

解决方案

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.

这篇关于UIView viewWithTag 0 问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-28 17:50