Creating iOS GUI elements from within an SDL app?

I’ve got an SDL game running on iPhone, mostly finished, and I’ve come to the point where I need to add iOS-specific GUI elements to it. Such as an interface for entering your name when you get a high score, for example. I’m fairly new to iOS programming, so I’m not sure if I’m doing something wrong, or if it’s a conflict due to how SDL starts up applications. Thought I’d ask here.

After my SDL app starts up, I use:

UIViewController *controller = [[UIViewController alloc] initWithNibName:@“highScoreNib” bundle:[NSBundle mainBundle]];

if (controller != NULL)
{
printf("\nLoaded UIView controller.\n\n");

[controller.view setUserInteractionEnabled:YES];

}

I get “Loaded UIView controller” in the console, but then on the setUserInteractionEnabled call, it spits out:

Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Could not load NIB in bundle: ‘NSBundle </var/mobile/Applications/39E005BF-BC5C-4F82-B337-F9F993408F21/Fireworks.app> (loaded)’ with name ‘highScoreNib’’
*** First throw call stack:

However my nib file is named highScoreNib.xib, and it IS in the “Copy Bundle Resources” section of the XCode project.

Am I just doing something stupid, or do I need to somehow “exit” from the SDL-created scene before I can display iOS-specific GUI stuff?

I think this line is wrong in two points

UIViewController *controller = [[UIViewController alloc] initWithNibName:@“highScoreNib” bundle:[NSBundle mainBundle]];

it should rather be

YourCustomViewController *controller = [[YourCustomViewController alloc] initWithNibName:@“highScoreNib” bundle:[[NSBundle mainBundle] resourcePath]];

+(mainBundle) just returns a pointer to the instance bundle, not to
the where the data is found; that is done by -(resourcePath) which you
call over the instance object.
Also you use nibs to create custom versions of a view controller by
subclassing one, so you should edit that and use the appropriate name
(i called it YourCustomViewController)

if you want to take a look at a project that heavily interacts with
ios and sdl you can read hedgewars sources at:
http://code.google.com/p/hedgewars/source/browse/

bye
VittorioOn Wed, Apr 25, 2012 at 11:34 PM, VernJensen wrote:

I’ve got an SDL game running on iPhone, mostly finished, and I’ve come to
the point where I need to add iOS-specific GUI elements to it. Such as an
interface for entering your name when you get a high score, for example. I’m
fairly new to iOS programming, so I’m not sure if I’m doing something wrong,
or if it’s a conflict due to how SDL starts up applications. Thought I’d ask
here.

After my SDL app starts up, I use:

UIViewController *controller = [[UIViewController alloc]
initWithNibName:@“highScoreNib” bundle:[NSBundle mainBundle]];

if (controller != NULL)
{
printf("\nLoaded UIView controller.\n\n");

[controller.view setUserInteractionEnabled:YES];
}

I get “Loaded UIView controller” in the console, but then on the
setUserInteractionEnabled call, it spits out:

Terminating app due to uncaught exception
’NSInternalInconsistencyException’, reason: ‘Could not load NIB in bundle:
‘NSBundle (loaded)’ with name ‘highScoreNib’’
*** First throw call stack:

However my nib file is named highScoreNib.xib, and it IS in the “Copy
Bundle Resources” section of the XCode project.

Am I just doing something stupid, or do I need to somehow “exit” from the
SDL-created scene before I can display iOS-specific GUI stuff?


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

Thank you!

[And for those who are confused, I had deleted my original message before Vittorio replied. But you can still read my original question in the quote above.]

Okay, I found this thread:

http://forums.libsdl.org/viewtopic.php?t=7352&sid=6b714337317597eaca026ae6be968b3e

I tried the code by Tim Angus, but I get this error when executing it:

*** Terminating app due to uncaught exception ‘NSInternalInconsistencyException’, reason: ‘Could not load NIB in bundle: ‘NSBundle </var/mobile/Applications/0994620B-3101-4503-B3F5-03F35E234AB1/Fireworks.app> (loaded)’ with name ‘SampleViewController’’

The thing is, I have SampleViewController added to the “Resources” section of my XCode project, AND it is also in the “Copy Bundle Resources” area of the Targets section. Why can’t it be loaded?

I also have SampleViewController.m and .h files in the project.

One more thing: the SampleViewController.h and SampleViewController.xib files were originally created and used in a different XCode project. Then I copied them over to the one that uses SDL. I don’t think copying them would cause any problems, versus using the “New…” command to create them from scratch within the target project, right?

Also, your suggestion to use:

bundle:[[NSBundle mainBundle] resourcePath]

is not right. That returns an NSString. But it needs an NSBundle.

I fixed the problem! Found this tip on stackoverflow:

“Right click your nib file in xcode and make sure its type is ‘file.xib’.”

Mine was of type “sourcecode.xib”. I have no idea what the distinction is, or how this happened, or why this would cause such a big problem, but changing it to “file.xib” did the trick! Finally, it’s working!!