This is mostly a stylistic question but I’ve been curious what others’ thoughts are since I started programming for the iPhone. When you have a UIView in your iPhone application and you need to access it elsewhere in your application (generally in another function in a view controller), do you like to tag the view with an integer and retrieve it with the viewWithTag: message, or do you generally set it to a property in the view controller for easy access later?
Saving it as a property obviously makes it easier to retrieve later, but I would think there is some (perhaps negligible) amount of memory that is saved by tagging a view instead of setting it as an object property.
I’ve generally been creating properties on my view controllers, mainly because I’m lazy, and retrieving views with viewWithTag: is annoying.
There is no memory to be saved by not using properties – a property is only generating a small bit of code that refers to an instance variable pointing to your view, that is going to be retained if you point to it or not.
Using viewWithTag would always be more expensive and slower, because that call has to go through the view hierarchy asking every view what the tag value is.
I always use IBOutlet instance variables, and add tags to controls sometimes where I don’t need to do anything except tell which particular control called a delegate method that could be activated by a few different controls. It’s a little less efficient but the code is easier to maintain in that case.