I'm trying to pass an image between 2 different views that are added as subclasses to the MainCanvasController. the image seems to get passed (it is shown, when printed to the Console) but it doesn't display anything... this is how I try to receive and display the image
-(void)receiveNumber:(C4Image*)number{
C4Log(@"number:%@", number);
number.center=self.canvas.center;
[self.canvas addImage:number];
receivedImage=number;
C4Log(@"received number: %@", receivedImage);
}
and here is how I post the image
[secondView receiveNumber:originalImage];
I don't really know what's going wrong. (well, honestly, I don't know at all...) So any hints are very much appreciated!
I had a look at your project and found the answer.
Your FirstView
object has a variable called secondView
, which is exactly the same name as the object in your main workspace. However, despite having the same name both of these are different objects.
I've done a couple things:
1) instead of using variables in the interface file for your objects, use properties.
2) create a SecondView
property in your FirstView
class
3) set the property of firstView
to the same object in your workspace, secondView
My FirstView.h
looks like:
@interface FirstView : C4CanvasController{
C4Label *goToSecondView;
}
@property (readwrite, strong) C4Window *mainCanvas;
@property (readwrite, strong) C4Image *postedImage;
@property (readwrite, strong) SecondView *secondView;
@end
My postNoti:
looks like:
-(void)postNoti{
C4Log(@"tapped");
[self postNotification:@"changeToSecond"];
[self.secondView receiveNumber:self.postedImage];
}
NOTE I got rid of the [SecondView new];
line.
The following is the part that you were missing
My workspace has the following line:
firstView.secondView = secondView;
Which sets the variable of the first view to have a reference to the secondView
object.
You hadn't done this, and so you were passing the image to an object that had the same name as the view that's visible from your main workspace's canvas.