dimanche 31 août 2014

Why is my external screen not responding?


Vote count:

0




I'm making an iOS app that interacts with an external monitor and the problem is that I can't find the reason why the "actions" don't have any effect.


Example: Trying to launch function "getData" (ExternalViewController) from BettingEntranceViewController.


Using separate storyboards for iPad and External monitor.


ViewController.h



#import <UIKit/UIKit.h>

@interface ViewController : UIViewController

@end


ViewController.m



#import "ViewController.h"
#import "ExternalViewController.h"

@interface ViewController ()

@property (strong, nonatomic) IBOutlet UITextView *loger;
@property (strong, nonatomic) UIScreen *extScreen;
@property (strong, nonatomic) UIWindow *extWindow;

@end

@implementation ViewController

- (void)logMessage:(NSString*)message
{
self.loger.text = [self.loger.text stringByAppendingString:message];
[self.loger scrollRangeToVisible:NSMakeRange([self.loger.text length], 0)];
}

- (void)screenDidSomething:(NSNotification *)notification
{
NSArray *screens;

screens = [UIScreen screens];
NSUInteger screenCount = [screens count];

if (screenCount > 1) {
self.extScreen = screens[1];
[self logMessage:@"Wuhu ext is!"];
} else {
self.extScreen = nil;
self.extWindow = nil;
}

self.extWindow = [[UIWindow alloc] initWithFrame:self.extScreen.bounds];
self.extWindow.screen = self.extScreen;

[self logMessage:[NSString stringWithFormat:@"External screen resolution: %f x %f \n", self.extScreen.bounds.size.width, self.extScreen.bounds.size.height]];

UIStoryboard *externalStory = [UIStoryboard storyboardWithName:@"External" bundle:nil];
ExternalViewController *externalTroller = [externalStory instantiateInitialViewController];
self.extWindow.rootViewController = externalTroller;

self.extWindow.hidden = NO;
}

- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(screenDidSomething:)
name:UIScreenDidConnectNotification
object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(screenDidSomething:)
name:UIScreenDidDisconnectNotification
object:nil];
}

- (void)viewDidDisappear:(BOOL)animated
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIScreenDidConnectNotification
object:nil];

[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIScreenDidDisconnectNotification
object:nil];
}


- (void)viewDidLoad {
[super viewDidLoad];
}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end


ExternalViewController.h



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

@interface ExternalViewController : UIViewController

- (void)getData;

@end


ExternalViewController.m



#import "ExternalViewController.h"
#import "BettingEntranceViewController.h"

@interface ExternalViewController ()

@property (strong, nonatomic) IBOutlet UITextView *logar;

@end

@implementation ExternalViewController

- (void)viewDidLoad {
[super viewDidLoad];

[self logMessage:[NSString stringWithFormat:@"Zloadano!"]];

//[self getData]
}

- (void)logMessage:(NSString *)message
{
self.logar.text = [self.logar.text stringByAppendingString:message];
[self.logar scrollRangeToVisible:NSMakeRange([self.logar.text length], 0)];
}

- (void)getData
{
[self logMessage:[NSString stringWithFormat:@"It works!"]];

}

- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

@end


BettingEntranceViewController.h



#import <UIKit/UIKit.h>

@interface BettingEntranceViewController : UIViewController

@end


BettingEntranceViewController.m



#import "BettingEntranceViewController.h"
#import "ExternalViewController.h"
#import "unistd.h"

@interface BettingEntranceViewController ()

@property (strong, nonatomic) ExternalViewController *externalTroller;

@end

@implementation BettingEntranceViewController


- (void)viewDidLoad {
[super viewDidLoad];

self.externalTroller = [[ExternalViewController alloc] init];
}


- (IBAction)sendGuest:(id)sender
{

[self.externalTroller getData];

}

@end


asked 1 min ago







Why is my external screen not responding?

Aucun commentaire:

Enregistrer un commentaire