How do I refer to a view controller in a subclass?

Posted by thekevinscott on Stack Overflow See other posts from Stack Overflow or by thekevinscott
Published on 2010-06-06T03:19:58Z Indexed on 2010/06/06 3:22 UTC
Read the original article Hit count: 277

Filed under:

Hey all, I'm currently teaching myself Objective C and I'm kind of stuck.

I'm building a backgammon game and I have a subclass, "Piece", which is being initialized, repeatedly, in BackGammonViewController.

In BackGammonViewController, if I do this:

UIImage *myImage = [ UIImage imageNamed: @"white-piece.png" ];

UIImageView *myImageView = [ [ UIImageView alloc ] initWithImage: myImage ];
[self.view addSubview:myImageView];
[myImageView release];

The image appears. However, I want to do this within my "piece" class. How do I refer to the "self.view" from within the piece class? Do I need to pass a reference to the view, into the "piece class" ? Or is there a global reference I can call from within the "piece class" ?

Thanks for your help.

© Stack Overflow or respective owner

Related posts about objective-c