4

I have a scroll view, which contains about 40-50 objects of different types. The object's types are defined in function of the object's location (for ex. if is the 5th object in the scroll view-> is's Object1, if it is the 11th object in the scroll view -> it's Object2 type etc.). With a for I am verifying each element of an array, and then putting them into the scroll view, with this method:

for (int i = 0; i < [myArray count]; i++){

 if (i < 10){
        NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"Class1" owner:nil options:nil];
        for (NSObject *obj in xib){
            if ([obj isKindOfClass:[Class1 class]]){
                classObject = (Class1 *)obj;
                break;
            }
        }
 } else if (i > 10 && i < 20){
        NSArray *xib = [[NSBundle mainBundle] loadNibNamed:@"Class2" owner:nil options:nil];
        for (NSObject *obj in xib){
            if ([obj isKindOfClass:[Class2 class]]){
                classObject = (Class2 *)obj;
                break;
            }
        }
      }
[scrollview addSubview:classObject];
}

My problem is, that it loads very slowly. What can I do to make it quicker?

4

1 に答える 1

4

IOS4+ 用にプログラミングしている場合は、代わりにUINibクラスを使用できます。キャッシュされたオブジェクトをロードし、必要なたびにコピーを作成します。このブログ投稿を参照してください。

于 2011-11-14T14:57:23.687 に答える