I have an interface like this:
@interface AView : UIScrollView
{
UIView* m_view1;
UIView* m_view2;
...
}
-(void) method1;
-(void) method2;
...
@end
I need to access views from methods of the interface. I need to create, release, re-create them and also set properties.
The problem is, some methods of the interface are running in different threads. Since these methods access same views I have issues like one thread trying to re-create a view when another thread is trying to set some properties of a view being recreated.
How should I synchronize access to views?
First of all, do you know you can ONLY call the methods of the UIView class (and it’s subclasses) in the main thread? But, if you are just doing create and release job in second thread, it’s OK to do it.
In addition, you can use
@synchronized() {object}to lock an object. But still, you can NOT call UIView’s methods in second thread (in Objective-C even set property is calling method) even you’ve locked it.