开发者

Does using many nib files has a performance penalty?

开发者 https://www.devze.com 2023-01-18 11:22 出处:网络
Is it better to put several views in one nib file instead? Thank开发者_C百科s, ReshefSome time ago I performed test like this:

Is it better to put several views in one nib file instead?

Thank开发者_C百科s, Reshef


Some time ago I performed test like this:

cellForRowAtIndexPath_method:
....
if (cell == nil) {
    NSArray *topLevelObjects = [[NSBundle mainBundle]
                                loadNibNamed:@"MyCell"
                                owner:nil options:nil];
    for ( id currObject in topLevelObjects ) {
        if ( [currObject isKindOfClass:[MyCell class]] 
            && [[currObject reuseIdentifier] isEqualToString:MyCellIdentifier] ) {
            cell = (MyCell *) currObject;
        }
    }
}
.....   

I had several cells in one file - MyCells.xib. And I got a HUGE (like from 1.5 - 2 seconds for loading "5-cells-in-one-file" file to 0.1 seconds to load a file with one cell per file on iPhone 2G) performance boost, when I split this file to a separate cells like MyCell1.xib, MyCell2.xib etc.

It could surprise you, but the lack of a performance was on a loadNibNamed invocation, not a "for" cycle.

So, I'd suggest to use separate files if you are going to load these views oftenly.

0

精彩评论

暂无评论...
验证码 换一张
取 消