[SDL] Showing a UIViewController on an SDL based iOS project

Tim Angus tim at ngus.net
Fri Jul 15 10:21:42 PDT 2011


Maybe this is useful for other people. It needs to be compiled as .mm in 
order to be callable from C++.

void PresentModalView( const char* viewName )
{
   SDL_SysWMinfo info;
   SDL_VERSION( &info.version );

   if( SDL_GetWindowWMInfo( window, &info ) )
   {
     UIWindow* uiWindow = (UIWindow*)info.info.uikit.window;
     UIView* view = [uiWindow.subviews objectAtIndex:0];
     id nextResponder = [view nextResponder];
     if( [nextResponder isKindOfClass:[UIViewController class]] )
     {
       UIViewController* viewController =
         (UIViewController*)nextResponder;

       // You can do some terrifying things with Objective-C
       NSString* className = [NSString stringWithUTF8String:viewName];
       Class ViewControllerClass = NSClassFromString(className);
       id subviewController = [[[ViewControllerClass alloc]
         initWithNibName:className bundle:nil] autorelease];

       [viewController presentModalViewController:
         subviewController animated:YES];
     }
   }
}



More information about the SDL mailing list