2013-07-01 64 views
0

我在滚动视图中创建1000个视图。这需要更多时间来加载视图。在滚动视图中创建1000个视图需要时间

wordsDetails *wordsObj; 
for(int i = 0; i<arrayOfWords.count;i++) { 
    UIView *viewForDisplay = [[UIView alloc]initWithFrame:CGRectMake(320*i, 0, 320, 440)]; 
    UILabel *wordLabel = [[UILabel alloc]initWithFrame:CGRectMake(30, 40, 240, 40)]; 
    wordLabel.backgroundColor = [UIColor clearColor]; 
    wordLabel.textColor = [UIColor yellowColor]; 
    wordLabel.font = [UIFont fontWithName:@"Didot" size:24.0]; 
    wordsObj = [arrayOfWords objectAtIndex:i]; 
    wordLabel.text = wordsObj.word;//[NSString stringWithFormat:@"sdssds - %i",i]; 
    [viewForDisplay addSubview:wordLabel]; 

    UITextView *textView = [[UITextView alloc]initWithFrame:CGRectMake(30, 100, 240, 100)]; 
    textView.text = wordsObj.meaning; 
    textView.editable = NO; 
    textView.textColor = [UIColor whiteColor]; 
    textView.font = [UIFont fontWithName:@"Didot" size:20.0]; 
    textView.backgroundColor = [UIColor clearColor]; 
    [viewForDisplay addSubview:textView]; 
    [fScrollView addSubview:viewForDisplay]; 
} 

有没有办法在线程中调用它。

+0

看看这个链接https://github.com/gmoledina/GMGridView – Leena

回答

2

不要像这样做。使用基于单元格的scrollview子类(表格视图或集合视图)或滚动你自己的。您的内容是屏幕的宽度,因此绝对不需要一次加载1000个屏幕的内容。

随着你只能创建多达需要显示的画面,而这些被回收和重新配置为新的内容来自屏幕上的细胞为基础的观点。

1

我创建一个滚动视图1000点的观点。

不这样做。用户不可能一次使用使用 1000个视图,因此不要一次创建它们。 WWDC 2010,2011和2012中有一些很好的视频,它们包括在滚动视图中平铺内容 - 查看一些伟大想法的内容。

滚动视图代表获得消息的滚动视图的内容移动,你可以使用这些消息来的正是时候添加的内容为它滚动到屏幕上,并删除它,它已经滚出了。这基本上就是UITableView和UICollectionView所做的,你可以像Jrturton所说的那样使用它们中的任何一个,或者你可以自己遵循相同的模式。

这不仅会加快您的滚动视图的创建,它也会让你的滚动顺畅,消耗比你需要,否则要少得多的内存。

相关问题