1 在xcode、iphone中标记多个UILabels
因此,我的应用程序中有许多包含相同文本的标签。我正在对它们进行本地化,并且想知道我是否可以用相同的数字标记它们并以这种方式分配新文本。
目前,当我测试时,它仅识别带有标签的第一个标签。
我真的很想让自己摆脱这些重复的出口
So I have many labels in my app that contain the same text. I am localizing them, and would like to know if its possible for me to tag them all with the same number and assign the new text that way.
currently when I have tested it only recognizes the first label with the tag.
I really want to save myself from having all these repeat outlets
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
是的,
您可以用整数标记它们,因为在继承树中
NSObject
是UIView
的超类,并且
NSObject
有一个名为的整数属性标签
。使用如下标签
Yes,
You can tag them with a integer number because in inheritance tree
NSObject
is the super class toUIView
,And
NSObject
has an integer property calledtag
.USE tag like below
从您的问题来看,您的问题是什么,但我假设您希望能够使用相同的文本更新位于应用程序内不同位置的所有 UILabel。
您可以创建一个全局头文件,其中包含一个 NSString,它保存所有标签的文本,然后在所有包含需要显示此文本的标签的视图控制器中
#include
这个头。然后,每当您更新全局标头中的 NSString 时,您都会更新当前正在查看或即将查看的所有标签。这可以在您的 IBAction 方法中完成,也可以实现 viewWillAppear:(BOOL)animated 方法。每当包含相关标签的视图进入视图时,它将应用全局标头中的 NSString 值并更新其标签。It is a little inclear from your question what your problem is, but I am assuming from your question that you want to be able to update all your UILabels which are located at different places within your app with the same text.
You could create a global header file that contains an NSString which holds the text for all your labels, and then
#include
this header in all view controllers which contain labels which need to show this this text. Then whenever you update the NSString in the global header you update any labels that are currently in view or about to be viewed aswell. This can be done from within yourIBAction
methods, as well as implimenting theviewWillAppear:(BOOL)animated
method. Whenever a view that contains relevent labels comes into view, it will apply the value of the NSString in your global header and update its labels.