loadNibName 方法太慢 - 如何让它更快?

loadNibName method is too slow - how to make it quicker?(loadNibName 方法太慢 - 如何让它更快?)
本文介绍了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+ 编程,你可以使用 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 方法太慢 - 如何让它更快?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Why local notification is not firing for UNCalendarNotificationTrigger(为什么没有为UNCalendarNotificationTrigger触发本地通知)
iOS VoiceOver functionality changes with Bundle Identifier(IOS画外音功能随捆绑包标识符而变化)
tabbar middle tab out of tabbar corner(选项卡栏中间的选项卡角外)
Pushing UIViewController above UITabBar(将UIView控制器推送到UITabBar上方)
Dropbox Files.download does not start when number of files in folder is gt; 1000(当文件夹中的文件数为1000时,Dropbox Files.Download不会启动)
How to target newer versions in .gitlab-ci.yml using auto devops (java 11 instead of 8 and Android 31 instead of 29)(如何在.gitlab-ci.yml中使用自动开发工具(Java 11而不是8,Android 31而不是29)瞄准较新的版本)