为了提高性能,我在后台线程中为我的滚动视图创建子视图,然后使用performSelectorOnMainThread
将事件发布到主线程,并将视图添加到其中的滚动视图中并将其添加到字体中。不过,我有时会遇到碰撞。在UIScrollview的后台线程中崩溃
当我检查我的后台线程。
if(nil == myView.view.superview)
如何在后台线程中执行此检查线程安全。如果我必须在主线程上执行,那么我需要更改设计,因此可以有办法将它发布到主线程并使用返回值。 我对同样的选择开放。
TIA,
普利文小号
编辑:
我已经实现UIScrollView的分页。然而,由于性能问题,并提高用户界面的响应我移动创建子视图到使用
[self performSelectorInBackground:@selector(loadPages:) withObject:nil];
在网页加载不同的线程,我这样做
if(nil == myView.view.superview)
{
Create the view
[[self performSelectorOnMainThread:@selector(refreshViews:) myView.view waitUntilDone:YES];
}
在刷新视图我添加子视图滚动视图,并把它放在前面。
[myScrollView addSubview:views];
[myScrollView bringSubviewToFront:views];
但是,获取添加和页面控制工作正常。滚动是好的,确实很顺利。但是,当我快速滚动(快速滑过屏幕)应用程序崩溃。
调试器说崩溃发生在负载页面if检查后的obj_msgSend。
编辑:堆栈跟踪 - 它崩溃在这次检查@synchronized。出于安全原因,我编辑了崩溃日志以删除项目特定的名称,但跟踪如下所示。
#0 0x33a06464 in objc_msgSend()
#1 0x314d6984 in -[UIViewController _loadViewFromNibNamed:bundle:]()
#2 0x314d5cb8 in -[UIViewController loadView]()
#3 0x313d6226 in -[UIViewController view]()
#6 0x00009920 in -[myViewController loadPages:] (self=0x12a2a0, _cmd=0x1eac1, abcd=0x0) at
#7 0x302d9198 in -[NSThread main]()
#8 0x302d2248 in __NSThread__main__()
#9 0x3110c88c in _pthread_start()
#10 0x31101a90 in thread_start()
那么我如何加快我的应用程序的响应速度?你可以请回答我的问题在这里.. http://stackoverflow.com/questions/5133731/how-to-make-ui-responsive-all-the-time-and-do-background-updating – 2011-03-04 09:01:17