I have an app that should display a Youtube video and I'm using the Youtube ios helper API.
I have a subclass of UITabBarController that is used to present two youtube videos and the UITabBarController is inside a NavController and is pushed to from a UITableViewController. So the setup looks like
[NAVController] -- relationship --> [UITableViewController] -- push --> [UITabBarController] -- relationship --> [CustomViewController]
Now my CustomViewController.h looks like:
#import <UIKit/UIKit.h>
#import "YTPlayerView.h"
@interface CustomViewController : UIViewController<YTPlayerViewDelegate>
@property (strong, nonatomic) YTPlayerView *youtubeView;
@property (strong, nonatomic) NSString *videoID;
@end
and my .m file has
#import "CustomViewController.h"
#import "YTPlayerView.h"
@interface CustomViewController ()
@end
@implementation CustomViewController
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
self.youtubeView.delegate = self;
self.view.backgroundColor = [UIColor blueColor];
self.youtubeView.frame = self.view.frame;
self.youtubeView.backgroundColor = [UIColor redColor];
[self.view addSubview:self.youtubeView];
NSLog(@"Subviews %lu", (unsigned long)[self.view.subviews count]);
NSLog(@"Subviews %@", self.views.subviews);
BOOL b = [self.youtubeView loadWithVideoId:self.videoID];
NSLog(@"Loaded? %d", b);
[self.youtubeView playVideo];
}
What I end up with is a navigation bar at the top (as it should be), a tab bar at the bottom (as it should be), but with a blue background instead of a red background (and needless to say, no Youtube video loads). When I run this, it prints
Subviews 0 Subviews ( ) Loaded? 0
Clearly the addSubView: call is not working.
I've seen this post, but it didn't help.
(For those unfamiliar with the youtube ios helper library:
The youtube-ios-player-helper is an open source library that helps you embed a YouTube iframe player into an iOS application. The library creates a UIWebView and a bridge between your application’s Objective-C code and the YouTube player’s JavaScript code, thereby allowing the iOS application to control the YouTube player.
(Using iOS 7 and Xcode 5.1)