Shabarinath Pabba
Shabarinath Pabba

Reputation: 1369

Uniquely differentiate UIViews

I have an application where every view controller subclasses from BaseViewController (A custom view controller that subclasses from UIViewController). I need to differentiate the subviews of a certain view controller's view from each other, from the BaseViewController. The application is pretty huge and each subview doesn't necessarily have a tag. What other ways are there to differentiate the sub views?

Upvotes: 0

Views: 51

Answers (2)

Lou Franco
Lou Franco

Reputation: 89172

XIB and Storyboard files are just XML. You could write a script to load the XML, put in tag attributes and save. The XML element name tells you what kind of view it is (button, imageView, etc).

Alternatively, if you can have different tags on each load, you can just programmatically tag the subviews in viewDidLoad

Upvotes: 0

Caleb
Caleb

Reputation: 124997

The application is pretty huge and each subView doesn't necessarily have a "tag". What other ways are there to differentiate the subViews?

That's exactly what the tag property is for -- differentiating between views that are otherwise similar, like each button in an array of buttons. You should only need to differentiate between the subviews managed by a single view controller at any given time; any given view should only be known by the view controller that manages its parent view, so the size of the app really doesn't change the tag property's utility.

The other obvious way to tell the difference between views is to use the fact that they're distinct objects, each with its own address. For example, say you've got a bunch of similar views representing people on a seating chart, and you want to keep track of which view goes with each person in the chart. One way to do that is to have your view controller maintain a NSDictionary where the keys are people and the values are the views.

Upvotes: 1

Related Questions