Vetterjack
Vetterjack

Reputation: 2505

Accessing View from ViewController

I created a ViewController in StoryBoard and linked it with the GamePanelViewController class. Furthermore I linked the view of the ViewController with a second class called GamePanel which extends of UIView.

How can I access to the view which is created automatically by StoryBoard to perform some methods I implemented to the GamePanel class which is linked to the view by identity inspector?

GamePanel.h:

#import <UIKit/UIKit.h>
#import "Plattform.h"

@interface GamePanel : UIView

@property (strong, nonatomic) NSMutableArray *plattforms;

- (void)initGamePanel;
- (void)drawPlattforms:(CGContextRef)gc;

@end

GamePanel.m:

#import "GamePanel.h"

@implementation GamePanel

@synthesize plattforms;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {

    }
    return self;
}

- (void)initGamePanel{
   self.backgroundColor = [UIColor redColor];

    self.plattforms = [NSMutableArray new];
    // Initialization code
    for(int i = 0;i<8;i++){
        for(int j = 0;j<6;j++){
            [self.plattforms addObject:[[Plattform alloc] initWithXCord:(14+j*37) andYCoord:(58+14+i*37)]];
            NSLog(@"Init");
        }
    }
}

Upvotes: 0

Views: 105

Answers (1)

JoeFryer
JoeFryer

Reputation: 2751

If you have actually linked the viewController's view property with your custom view, then you can simply use self.view within you viewController to access it.

If you have just dragged a UIView onto your viewController in your storyboard (and not linked it to the viewController's view property), you will need to create an IBOutlet for it (control-drag from the view to your interface, and give it a name), then you can reference it with the name you give it e.g. self.myView.

Upvotes: 3

Related Questions