loadNibName方法太慢-如何使其更快? [英] loadNibName method is too slow - how to make it quicker?

查看:132
本文介绍了loadNibName方法太慢-如何使其更快?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个滚动视图,其中包含大约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 +进行编程,则可以使用此博客文章.

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方法太慢-如何使其更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆