iphone - UIView ivar vs. tagging a local UIView var -


Scenario 1: For a UIViewController, it is better (1) Create an ivar for a UIView that I use again in 1.

loadView <2 code> out of 2 functions? Or, (2) I should just tag it in loadView and then see the - (UIView *) view with the view: (NSInteger) tag to reuse it in other tasks to do? I'm guessing that 1 option increases memory by the size of the pointer, so 32/64-bits, and the accelerator forms (I think the @property is declaring & amp; Code> @synthesize ), and then issuing ivar in dealloc and setting it to zero in viewDidUnload Is ... and that option saves 2 memory, there is less setup code, but its tag has some processing time to find the scene and Ode costs of additional code. Am I right about this?

In this scenario, it is best to use an ewer, but I'm not sure.

Scenario 2: UIView for custom sub-classes that contains 5 SubViews? Keeping in mind that I have about 30 instances of this custom subclass in a custom time (they will be subviews of tableViewCell .), I should use 5+ income for subviews or I All of these should be tagged?

In this scenario, I am thinking of all the memory saved by tagging them, they will be eligible for small display hits to search with the - (UIView *) view: (NSInteger ) Tags .

Thoughts?

Thank you!

The difference in memory usage is negligible (until You do not consider 100 of these, then you can pay attention to those ideas), you should probably consider what your code will be more readable and maintenance. I personally think that using an ivores will be more readable, but it is also possible that the use of tags for your particular tags will be more readable.

When writing code, I always try to think about the person who can read the code for a year or two, that person may be me, or it can be someone else, but someone Even by the way, I know that the person would appreciate the readable code.

At least 128 MB of RAM is less thanks to me for saving 1kg of memory on one memory.

Comments