loadNibName方法太慢了

编程入门 行业动态 更新时间:2024-10-27 19:15:14
loadNibName方法太慢了 - 如何让它更快?(loadNibName method is too slow - how to make it quicker?)

我有一个滚动视图,其中包含大约40-50个不同类型的对象。 对象的类型是根据对象的位置定义的(例如,如果是滚动视图中的第5个对象 - >是Object1,如果它是滚动视图中的第11个对象 - >它的Object2类型等)。 使用for我将验证数组的每个元素,然后使用此方法将它们放入滚动视图中:

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]; }

我的问题是,加载速度非常慢。 我该怎么做才能更快?

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.

更多推荐

本文发布于:2023-08-03 05:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1383909.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:慢了   方法   loadNibName

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!