views:

32

answers:

1

Perhaps there's a better way to set this up so I'm open to suggestions.

But here's what I'm doing. I have a main UIView. On top of that I have a UIImageView and another UIView. When the UIImageView changes, I want to change the second UIView. So I have a class for it and the IB object's type is set to the class. In the .m of that class is a drawRect method that draws some rectangles. Also in the .m is a NSMutableArray property that is synthesized. I created an instance of that class in the controller of the main view.

The problem: despite the fact that the drawRect works fine when the app starts (as traced in the debugger,) when the UIImageView changes I call a "setNeedsDisplay" on the instance variable of the second view after updating the @synthesize'd array but the drawRect does not get called.

I think it has to do with instances. I wouldn't think threading would be an issue here. I just want to draw in a separate area of the screen based on an image also displayed.

A: 

OK, for those who see this and are having a similar issue...

It was indeed an 'instance' problem. I had created the secondary UIView in IB. I think because I had established a connection there, the code ran fine on startup.

The fix was to create the subview programmatically and add it to the main view. That way there was only the one instance. Updating the @synthesize'd array variable and the subsequent calls to drawRect (via setNeedsDisplay) went to the one instance of the secondary view, the one I had added as a subview to the main one. Problem solved.

Troy Sartain