views:

32

answers:

2

Hello,

I want to renew a subview which is created like this:

CGRect keyLabelRect = CGRectMake(2, [heightofrow intValue]*i, [breitescroller2 intValue]-2,[heightofrow intValue]);
UILabel *keyLabel = [[UILabel alloc] initWithFrame:keyLabelRect];
[Inhalt1 addSubview: keyLabel];
[keyLabel release];

By calling a method, "breitescroller2" got a new value and this term is called a second time and a third time and so on. My problem is, that the "older UILabel" with the old position stay at the view, but i want to replace it with the new position. Is there a simple method? by deleting the whole subview (keyLabel removeFromSuperView] the newer one's are deleted too.

Thanks for help!

A: 

I'm pretty sure you first need to remove the old label via removeFromSuperview.

ennuikiller
i changed my methods by removing "UILabel *keyLabel" and now i create the Label in the header, now i can use "removeFromSuperview", thx.
Jonathan
+3  A: 

If you're doing it like that, would it not make more sense to simply modify the properties of the existing UILabel and not keep creating a new one each time? It seems to me that doing it the way you are now, especially since you want to replace the old one with the new one, is a bit inefficient memory-wise.

I'm only a beginner at working with Cocoa and Obj-C, though, so I might be missing something that makes my suggestion unfeasible.

JAB
yes, you are right, i will change my methods to optimize the performance.
Jonathan
Correct: Why keep recreating it? It's not really memory that's the problem but CPU overhead. Far more efficient to just change the label's text. On a mobile device where CPU cycles (and, by extension, power) are important, efficiency should be one of your top concerns.
Joshua Nozzi