1

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!

suMi
  • 1,536
  • 1
  • 17
  • 30
  • Try this first: `C4Image *newNumber = [number copy];` then change the center of the new number, then add the new number to the canvas. – C4 - Travis Oct 24 '13 at 16:38
  • just tried. it doesn't make a difference – suMi Oct 25 '13 at 08:39
  • 1
    I posted the code on GitHub in case you wanna have a look at the full thing: https://github.com/susemiessner/Urban-Alphabets/tree/master/Test_PostingImage (did I say thanks for your constant help already?! It's amazing! thanks!) – suMi Oct 25 '13 at 10:04

1 Answers1

1

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.

C4 - Travis
  • 4,502
  • 4
  • 31
  • 56
  • thanks!!! I'm learning new things in C4/objective C every day! (such as working with properties right now). – suMi Oct 27 '13 at 09:14
  • Great! One of the core ideas behind C4 is that as you learn to work with it, you're also learning ObjC because the design of the API reflects the same patterns. – C4 - Travis Oct 27 '13 at 19:11