UIScrollView花费了太多时间(UIScrollView taking too much time)

编程入门 行业动态 更新时间:2024-10-14 06:25:03
UIScrollView花费了太多时间(UIScrollView taking too much time)

我试图在我的应用程序中放置一个ScrollView有1000,000个记录,这个scrollView将在应用程序启动时加载,所以应用程序没有运行,直到百万1000 000记录需要花费很多时间,我想知道是否有任何在加载记录时显示应用程序和scrollView的方法(在添加记录时显示scrollView),在代码下方使用:

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self loadIt]; } - (void)loadIt{ float startX = 0; float startY = 0; [_bigScroll setContentSize:CGSizeMake(320, 312500)]; _bigScroll.pagingEnabled = NO; for (counter=0; counter<999999; counter++) { UIButton *tester=[[UIButton alloc] initWithFrame:CGRectMake(startX, startY, 10, 10)]; if (counter % 2 == 0) { [tester setBackgroundColor:[UIColor whiteColor]]; } else { [tester setBackgroundColor:[UIColor grayColor]]; } [_bigScroll addSubview:tester]; [tester release]; if (startX == 320) { startX = 0; startY += 10; } else startX += 10; NSLog(@"counter = %d", counter); } }

请指教。

am trying to place a ScrollView in my app that has 1000,000 record, this scrollView will load when the app launches, so the app is not running until the million 1000 000 record which takes a lot of time, i was wondering is there any way to show the app and the scrollView while records are loading (show the scrollView while adding its records), below the code am using:

- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. [self loadIt]; } - (void)loadIt{ float startX = 0; float startY = 0; [_bigScroll setContentSize:CGSizeMake(320, 312500)]; _bigScroll.pagingEnabled = NO; for (counter=0; counter<999999; counter++) { UIButton *tester=[[UIButton alloc] initWithFrame:CGRectMake(startX, startY, 10, 10)]; if (counter % 2 == 0) { [tester setBackgroundColor:[UIColor whiteColor]]; } else { [tester setBackgroundColor:[UIColor grayColor]]; } [_bigScroll addSubview:tester]; [tester release]; if (startX == 320) { startX = 0; startY += 10; } else startX += 10; NSLog(@"counter = %d", counter); } }

Please advice.

最满意答案

有没有办法在加载记录时显示应用程序和scrollView?

尝试使用[self performSelector:@selector(loadIt) withObject:nil]; or [self performSelector:@selector(loadIt) withObject:nil afterDelay:0.2]; [self performSelector:@selector(loadIt) withObject:nil]; or [self performSelector:@selector(loadIt) withObject:nil afterDelay:0.2]; 在执行此方法之前,它不会阻止您的UI。

你正在加载大量的记录。 实际上你不应该加载所有记录。 你应该使用像tableview这样的机制,只使用那些在scrollview的可见区域中的记录。 在滚动之前不要加载新行,您应该重复使用行或视图,以便加快滚动速度。

Is there any way to show the app and the scrollView while records are loading ?

Try to use [self performSelector:@selector(loadIt) withObject:nil]; or [self performSelector:@selector(loadIt) withObject:nil afterDelay:0.2]; It will not block your UI until the execution of this method.

You are loading lots of records. Actually you should not load all records at at time. You should use mechanism something like tableview is using i.e.load only those record which are in visible area of scrollview. Don't load new rows until the scroll and you should reuse row or views so speedup the scrolling.

更多推荐

本文发布于:2023-07-07 21:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1068455.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:太多   时间   花费了   UIScrollView   time

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!