Ios UIScrollView填充速度慢

Ios UIScrollView填充速度慢,ios,objective-c,performance,uiscrollview,uicollectionview,Ios,Objective C,Performance,Uiscrollview,Uicollectionview,我在iOS7+应用程序中有一个分页的UIScrollView,每个页面都包含一个UIView,其中包含一个UITextView 这是填充它的代码 // Looping through results for(int i = 0; i < [data count]; i++) { // Creating view UIView *view = [[UIView alloc] initWithFrame:CGRectMake(i * scrollSize.width, 0, s

我在iOS7+应用程序中有一个分页的
UIScrollView
,每个页面都包含一个
UIView
,其中包含一个
UITextView

这是填充它的代码

// Looping through results
for(int i = 0; i < [data count]; i++) {
    // Creating view
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(i * scrollSize.width, 0, scrollSize.width, scrollSize.height)];

    // Creating the UITextView
    UITextView *theText = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, scrollSize.width * 0.9, scrollSize.height * 0.5)];
    theText.backgroundColor = nil;
    theText.scrollEnabled = NO;
    theText.selectable    = NO;
    theText.center = CGPointMake(view.frame.size.width / 2, view.frame.size.height / 2);

    // Assigning properties
    theText.attributedText = [[NSAttributedString alloc] initWithString:[data objectAtIndex:i] attributes:attribute];

    // Centering the label and assigning font size
    theText.font = [UIFont fontWithName:FONT_NAME size:fontSize];
    theText.textColor = FONT_COLOR;

    // Adding label to view and view to scrollView
    [view addSubview:theText];
    [scroll addSubview:view];
}
//在结果中循环
对于(int i=0;i<[数据计数];i++){
//创建视图
UIView*view=[[UIView alloc]initWithFrame:CGRectMake(i*scrollSize.width,0,scrollSize.width,scrollSize.height)];
//创建UITextView
UITextView*theText=[[UITextView alloc]initWithFrame:CGRectMake(0,0,scrollSize.width*0.9,scrollSize.height*0.5)];
text.backgroundColor=nil;
text.scrollEnabled=否;
text.selective=否;
text.center=CGPointMake(view.frame.size.width/2,view.frame.size.height/2);
//分配属性
text.attributedText=[[NSAttributedString alloc]initWithString:[data objectAtIndex:i]属性:属性];
//将标签居中并指定字体大小
text.font=[UIFont-fontWithName:font\u NAME-size:fontSize];
text.textColor=FONT\u COLOR;
//将标签添加到视图和将视图添加到滚动视图
[视图添加子视图:文本];
[滚动添加子视图:视图];
}
它相当慢,阻塞了应用程序的UI。(30个元素的
数据
约0.38秒)

我试图通过不每次创建子视图来优化它,但看起来我无法复制原始对象

我怎样才能使它更快?我可以重用循环中的某些元素吗?我应该使用类似于
UICollectionView
的东西吗?
UICollectionView
是否适合我的需要


谢谢

典型的方法是只在可见视图的左/右创建视图,并在滚动时创建下一个视图。您还可以通过重置内容和滚动完成后重置滚动视图偏移量来重用这三个视图。嗯,看起来很整洁!我要试试看!有什么例子吗我知道这不符合主题,但你试过icarousel框架吗?苹果公司也有一些示例代码和几年前关于滚动视图和分页的WWDC会话,但我经常使用的是carouselview