views:

24

answers:

1

I have a problem. I am using three20 and am using TTYoutubeView, this problem does not necessarily require knowledge of three20 to fix I think.

My issue is, i have a custom drawMethod on my navigationBar, however, when i load a youtube video, i need to tell it to ignore my custom draw method (this isn't a problem, i have a global BOOL that can do this).

My problem is, there is no way i can detect when the youtube video loads, it is launched via an object within a UIWebview, so no UITouches to catch, and I don't fancy subclassing the UIWebview, as after the youtube video has been dismissed, i have no way to catch this either.

What i require, is a method that whenever my navigationbar is drawn asks 'What class is the current viewController', then i can tell it what to draw dependent on what is being displayed.

NSLog(@"%@",[TTNavigator navigator].topViewController);
NSLog(@"%@",[TTNavigator navigator].visibleViewController);

I am logging out the viewControllers in my draw method, this works perfectly, my code logs as follows

2010-09-08 16:39:23.171 MyApp[3512:307] <HomeController: 0x264df0>
2010-09-08 16:39:23.174 MyApp[3512:307] <HomeController: 0x264df0>

The problem is, when the youtube video loads, it seems to load a modalViewController, my code still logs out the viewController that is underneath this modalController. It does not tell me what is on top.

Detecting the viewController seemed like a bright spark when i thought of it, and it still is a good idea as far as i'm concerned. I'm just at a loss as to how I can find out what view is currently on top. (as topViewController and visibleViewController don't seem too do this accurately)

A: 

after alot of searching, i found that I simply couldn't get any kind of callback from the youtube object or the webview regarding happenings going on within it without extensive subclassing.

I realised that the navBar is drawn AFTER the viewController that is pushed loads. Also, that modalViewController's sit ontop of the topViewController in the 'stack' on the navigationController and do not require them to have their navBar's redrawn when the modalViewController is dismissed...

In the end i did this.

In my navBar draw method, AFTER it had checked the BOOL and drawn appropriately, i do a check.

if ([[TTNavigator navigator].topViewController isKindOfClass:[VideoController class]]) {
    kDrawNavBar = FALSE;
}

This means that once my videoController (the one with the youtube webview/button in it) loads, the BOOL changes. So that when the new modalViewController that is out of my hands is loaded, it draws the default navBar, not my custom image.

All that was left to do, was override the back button action on my navBar controller for the videoController and set kDrawNavBar = TRUE; So that upon exiting this view, and going back to my 'home screen', everything was back to normal.

Hopefully this will help someone else in the future.

Bongeh