处理线程中变量的问题
我正在开发一个用于显示文件系统内容的应用程序。我有两种类型的显示
1)OutlineView
2)IKImagebrowserView
用户可以在视图之间切换。我将当前视图对象维护在全局变量 currentview
中,因为多个控制器需要访问它。
现在,每当用户切换视图时,一个控制器(在线程上运行)就会更改此全局变量。但是,我有另一个控制器(取决于某些数据库操作),
[currentview reloadData];
每当我在视图之间快速切换时,它会使用 Now 不断刷新当前视图,这些线程中的当前视图对象存在问题,并且应用程序崩溃。 崩溃报告显示应用程序在线崩溃
[currentview reloadData];
有没有解决方案?
I am developing an application for showing the filesystem contents . I have two types of displays
1)OutlineView
2)IKImagebrowserView
The user can switch between the views . I am maintaining the current view object in a global variable currentview
as multiple controllers need to access it.
Now whenever the user switches views, one controller (running on a thread) changes this global variable. However I have another controller which (depending on some DB operation) continuously refreshes the currentview using
[currentview reloadData];
Now whenever I switch rapidly between the views, there is an issue with the currentviewobject among these threads and the application crashes.
The crash report shows that the aplication crashes on the line
[currentview reloadData];
Is there any solution for this ??
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试使用
它会创建一个排他锁,这将阻止其他线程同时访问它。
try using
this will make a exclusive lock which will prevent it from being accessed by other threads simultaneously.