Hello all I have 2 basic questions. I just learnt how to load a custom xib for the first time from code via ([[NSBundle mainBundle] loadNibNamed).

  1. Just wondering how do I get the xib to expand to full screen on every device it goes on (iPad/iPhone etc)?

At the moment the xib's size is kept to 600,600 on every device. I was hoping I'd be able to make the settings changes in Interface Builder Simulation Size metrics setting etc I have the xib's Simulated Metrics Size on "Inferred" but it does not seems to make a difference what I set it to.

GameScene.m
#import "GameScene.h"
#import "controlsViewController.h"

-(void)didMoveToView:(SKView *)view {
//other game stuff

//load xib
[super view];
controlsViewController *ControlsViewController = [[controlsViewController alloc] init];
[self.view addSubview:ControlsViewController];
//position on screen in the center
ControlsViewController.center = CGPointMake(CGRectGetMidX(view.frame),
                                            CGRectGetMidY(view.frame));
}

controlsViewController.m
#import "controlsViewController.h"
@implementation controlsViewController

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
    [[NSBundle mainBundle] loadNibNamed:@"controlsViewController" owner:self options:nil];
    NSLog(@"CVC Frame Size: %@", NSStringFromCGRect(self.view.bounds)); //keeps showing 
    self.bounds = self.view.bounds;
    [self addSubview:self.view];
}
return self;
}

controlsViewController.h
#import <UIKit/UIKit.h>

@interface controlsViewController : UIView
@property (strong, nonatomic) IBOutlet UIView *view;
@end
  1. Also I have a button in this xib file that I'd like to be connected to a method that does not belong to its own controller controlsViewController.m but to run a method that is inside GameScene.m. How do I get it to be able to run a method there? I know I can easily drag from the xib to controlsViewController.m to create an action but it won't drag to GameScene.m as expected. How do I get around that?

Any help would be great

1

There are 1 answers

1
Rob Sanders On

For the first question you can get the screen size of a device by calling; [[UIScreen mainScreen] bounds]; this returns a CGRect.

For the second question you cannot link an action in one view controller to a button in another. This is because the first view controller may not be instantiated (I.e. Around in memory) when the second one is. You could use a singleton class to share resources between view controllers or you could use the responder chain.

You need to get used to the fact that view controllers are isolated and there's no getting around that for good reason and therefore most apps use singletons to share data globally around the app.

Read the best practices for programming amd making apps documentation by Apple