問題描述
我有一個滾動視圖,其中包含大約 40-50 個不同類型的對象.對象的類型是在對象位置的函數中定義的(例如,如果是滾動視圖中的第 5 個對象-> 是 Object1,如果它是滾動視圖中的第 11 個對象-> 它是 Object2 類型等).使用 for 我正在驗證數組的每個元素,然后使用以下方法將它們放入滾動視圖中:
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?
推薦答案
如果你正在為 IOS4+ 編程,你可以使用 UINib 類.它將加載緩存的對象并在每次需要時創建一個副本.請參閱 這篇博文.
If you are programming for IOS4+, you can use the UINib class instead. It will load a cached objects and create a copy each time needed. See this blog post.
這篇關于loadNibName 方法太慢 - 如何讓它更快?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!