Design by .xib or .m

Friends, I have an application, ten pages, but full of buttons (with background images), large background images, field image for a set of controls, etc. I developed all those that are in XIB files. It works fine, but after a few minutes my application displays "Received Memory Warning Level = 1". Some developers suggest that I do projects using .m files rather than doing this in an XIB file. They say this will reduce the memory usage of graphics.

It's true? Will developing a .m file reduce memory usage? Please advice, thanks.

+3
source share
3 answers

, ? XIB . , .

XIB . , XIB, , , .

retain release? Xcode, Tools, , .

+4

Nib . , Nib - , .

Nib Interface Builder . , Nib , ; , , , ! . , , Nib , , , .

http://developer.apple.com "nib", , , " - Nib", Nib ". , Nib .

0

, , . , , . , , , .xib. Infact, - , .

It’s actually very easy to understand why (I was surprised when I heard). Basically, every thing in a .xib file is an object. When you have many objects, you run out of memory. What you need to do is run a code similar to the following when changing pages.

- (void) changeToPageOne {
    [theSecondElement release];
    //Then you make the new interface element
    UIImageView *theElement = [[UIImageView alloc] initWithFrame:(CGRect)];
    //You will need the coordinates from the .xib file for the CGRect there
    [theElement setImage:(UIImage*)];
    [theView addSubview:theElement];
}

You do the same for the next page. The problem here is that you will need to track the UIImageView, but basically it is a local variable. You can add it to the array and simply delete the objects in the array when changing pages. Hope this helps!

-3
source

All Articles