我试图在我的应用程序中放置一个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.
更多推荐
发布评论