0

I tried to add picture to my NSView with calling method from another class.
How I must init firstClass instance in secondClass?
Code example:

firstClass.m:

//method for adding picture
-(void) createPoint:(NSPoint)location{
  point = [NSImage imageNamed:@"point3"];
  point.size = NSMakeSize(21, 21);
  pView = [[NSImageView alloc] init];
  [pView setFrameSize:crimePoint.size];
  [pView setImage:crimePoint];
  [pView setFrameOrigin:CGPointMake(location.x-10, location.y-10)];
  [self addSubview:pView];   
}

secondClass.m:

- (IBAction)updateButton:(id)sender {
  [firstC createPoint:NSMakePoint(300, 300)]; // FirstClass* firstC; (alloced and inited)
}

This one looking same, but i don't understand how to use that answer:
Calling Method From Another UIViewController Has No Visible Effect

Community
  • 1
  • 1
Dude
  • 21
  • 5
  • You look like you're on the right track. I dont know what the init method for your FirstClass is but if it was "init" then you would do `FirstClass* firstClass = [[FirstClass alloc] init]`; – Aggressor Sep 24 '14 at 18:42
  • `firstC` is an ivar of `SecondClass`? What's the problem you're facing, exactly? Your code comment says "alloced and inited". – jscs Sep 24 '14 at 18:48
  • @Aggressor, for my situation it doesn't work. Coz `FirstClass* firstClass = [[FirstClass alloc] init]` just duplicate class, but I need to add picture to current view. Check link in the end of my post, mb U will understand what I mean. Sorry for my english >_ – Dude Sep 24 '14 at 18:50
  • You have a `FirstClass` instance in a storyboard, then? – jscs Sep 24 '14 at 18:51
  • @JoshCaswell i mean that this variant doesn't work. This link must to help: http://stackoverflow.com/questions/24312447/calling-method-from-another-view-controller-not-working-c-objective-xcode , but i don't understand where i must put `(SecondViewController *)self.presentingViewController` – Dude Sep 24 '14 at 18:52
  • Can you explain the relationship between `SecondViewController` and `FirstClass` a little more? – jscs Sep 24 '14 at 18:54
  • @JoshCaswell , yes, I have instance in the Implementation – Dude Sep 24 '14 at 18:54
  • @JoshCaswell FirstClass is nsview class that looking like image screen with other image. SecondClass is nswindow class with button that called method from FirstClass to add image. – Dude Sep 24 '14 at 18:58
  • @danh can u help me with my problem? just say what code and where i must put it in my situation. coz i don't understand what u mean in [this post](http://stackoverflow.com/questions/24312447/calling-method-from-another-view-controller-not-working-c-objective-xcode) (I have problem with english...) – Dude Sep 24 '14 at 20:57

0 Answers0