loadNibName 方法太慢 - 如何使其更快?

发布于 2024-12-15 04:17:54 字数 942 浏览 4 评论 0原文

我有一个滚动视图,其中包含大约 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧情别恋 2024-12-22 04:17:54

如果您正在针对 IOS4+ 进行编程,则可以使用 UINib 类代替。它将加载缓存的对象并在每次需要时创建一个副本。请参阅这篇博文< /a>.

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文