Is it possible to access an IB object (say, a UILabel) without declaring a IBOutlet property?
I have more than 20 labels that I need to update at runtime, and I was wondering if it could be possible to access them without having to declare properties and outlets for all of them. I tried to assign a unique tag to each, and access them trhough the view in my view contoller, something like this:
self.view.myLabel1.text = @"Some text";
But it did not work. Is there a way 开发者_Go百科to accomplish this?
Thanks
The tag-approach is the right one, but you have to access the labels differently. Assuming self.view
is the parent view of the labels and all labels have an unique tag (integer), you can get them like this:
UILabel *label = (UILabel *)[self.view viewWithTag:1];
As far as i know Xcode does not know nothing about your xib UIElements if you don't declare them. I had similar dilemma long time ago, and since then, when i have a large number of objects from the same kind i prefer to make them reusable by creating them programmatically.
good luck
精彩评论