Combining OpenGL ES template and Utility template - iphone

I would like to have an OpenGL view with an utility application.
What I do:
I create an OpenGL ES application template and a Utility Application template.
I copy the files EAGLView.m and h, and the five ESrenderer. files from the Opengl project to the utility project.
I copy these lines from the OpenGl project to the Utility project: (in utilityAppDelegate.m)
- (void)applicationDidFinishLaunching:(UIApplication *)application {
...
[glView startAnimation];
}
- (void) applicationWillResignActive:(UIApplication *)application
{
[glView stopAnimation];
}
- (void) applicationDidBecomeActive:(UIApplication *)application
{
[glView startAnimation];
}
- (void)applicationWillTerminate:(UIApplication *)application
{
[glView stopAnimation];
}
- (void)dealloc {
...
[glView release];
...
}
And in the utilityAppDelegate.h I add:
#class EAGLView;
EAGLView *glView;
#property (nonatomic, retain) IBOutlet EAGLView *glView;
I go to the view's identity inspector, and change the class identity to EAGLview.
I open the mainview.xib and mainwindow.xib and drag the app_delegate from the mainwindow.xib, to be able to connect the glView outlet to the view.
(Don't know if this is the way to do it, but that's the only way I could connect the glView variable to the view)
When I build and run, the multi colored square show up on the screen, but it does not animate!
When I debug, the glView variable is 0 in applicationDidFinishLaunching, and the startAnimation is not called. I suspect this has something to to with the way the outlet is connected to the view? Probably not connected. :-)
The mistake is probably obvious, but I have only been 5 weeks on this platform.
What is missing? What have I done wrong?
Thank you!

I don't know if you've provided enough information to tell exactly what's going wrong in your case. However, I'd suggest that you look at the source code for my iPhone application Molecules.
While it is a little more complex, the application is based on those two templates. It uses an OpenGL ES main view (where a 3-D molecular rendering is presented), and a table view / navigation controller on the flipside (for switching molecular structures, examining their properties, and downloading new ones). You could review that example to see what you might be doing wrong, or even just replace my rendering and view code with your own.

I got the solution in another forum:
http://iphonedevbook.com/forum/viewtopic.php?f=25&t=3192&sid=9cf79468b81a8fd6c9d9020958d33388
Basically, just add the glView outlet to the MainViewController instead of the AppDelegate.

Related

cocos2d: animation stopped. Integrate Cocos2D and UIKit

I already integrate Cocos2D and UIKit.
I have the navigation among the views and the first time that I open the cocos view, it works.
But when I return to my main menu, the log console displays:
cocos2d: animation stopped
After that, if I try to get in to the cocos2D view again, the animation does not start.
What can I do to solve this?
I followed this tutorial but it donĀ“t help
http://www.raywenderlich.com/4817/how-to-integrate-cocos2d-and-uikit
There have been issues regarding this. There was a similar discussion in another SO Question.
Whenever I want to include UIKit elements, I tend to do it the other way round.
With the CCUIViewWrapper code at: https://github.com/splhack/CCUIViewWrapper
This maybe be different depending on the version of cocos2d you are using, but stopAnimation should be being called on CCDirectorIOS.m:viewDidDisappear and startAnimation should be being called on viewWillAppear. So I would set breakpoints there to make sure it is being called on. And if your -(void) mainLoop:(id)sender is running.
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
[self startAnimation];
}
-(void) viewDidDisappear:(BOOL)animated
{
[self stopAnimation];
[super viewDidDisappear:animated];
}
If you want to investigate further the mainLoop calls drawScene and if it is not isPaused, then the CCScheduler will update the CCActionManager which runs all of the animations.
Hope this helps.

objective-c : How to move from AppDelegate in Universal app?

I am developing a Universal app where I have
imageTracker_iPhone.xib
imageTracker_iPad.xib
imageTracker.h
imageTracker.m
I want to move from AppDelegate_iPhone to imageTracker. I am doing this in didFinishLaunchingWithOptions but its not working before this code I was using
imageTracker *vRDi = [[imageTracker alloc] initWithNibName:#"imageTracker_iPhone" bundle:nil];
[self.view addSubview:vRDi.view];
but it gave error request for member 'view' in something not a structure or union
. Even if code is like
[window addSubview:vRDi.view];
now The function is like below and its not working. I want to move from AppDeligate to imageTracker. please help
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
[window addSubview:imageTracker.view];
[self.window makeKeyAndVisible];
return YES;
}
In this case It does not move to imageTracker_iPhone because did not tell any where to move to this file, so want to know that HOw to tell that which file to move either imageTracker_iPhone or imageTracker_iPad.
You probably want to set the delegate window's rootViewController to make your first controller active. (If you create a new test app from a single controller, non-storyboard template, you can see the kind of code that's needed in didFinishLaunchingWithOptions:.)
Edit: Actually, it's even easier than that. If you specify a universal app when creating a single view controller project, it creates the exact code to test which kind of device and load the matching .xib file. (Xcode 4.2, at least.)
your code should be something like this
imageTracker *vRDi;
Bool isiPhone = UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone;
if(isiPhone)
vRDi = [[imageTracker alloc] initWithNibName:#"imageTracker_iPhone";
else
vRDi = [[imageTracker alloc] initWithNibName:#"imageTracker_iPad";
and make sure that your connect view outlet in both xib's and the file owner is "imageTracker" Class.

Add Zooming to UIScrollView

I've been doing the tutorials in the Big Nerd Ranch Iphone development book and ran into an issue I can't solve or find an answer for.
The App (Hypnosister) basically just draws a bunch of concentric circles and places some text on the screen using the DrawRect method. I got that to work and I was able to add scrolling ot the view but can't add the ability zoom. I've checked my code 100 times and can't figure it out. I think they used an earlier version of the OS and I am using 4.2. Did something change? Can you find the issue?
Here is the relevant code:
#interface HypnosisterAppDelegate : NSObject <UIApplicationDelegate,
UIScrollViewDelegate>
{
UIWindow *window;
HypnosisView *view;
}
and this goes in the application didFinishLaunchingWithOptions part:
[[UIApplication sharedApplication]
setStatusBarHidden:YES withAnimation:UIStatusBarAnimationFade];
and method gets called after that method closes:
- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView
{
return view;
}
HypnosisView is a UIView class that does the drawing. Thanks for the help.
Just downloaded the examples for the book from the Big Nerd Ranch website and it works fine on the simulator under 1OS 4.3. Did you add these lines of code to didFinishLaunchingWithOptions:
// Enable zooming
[scrollView setMinimumZoomScale:0.5];
[scrollView setMaximumZoomScale:5];
[scrollView setDelegate:self];
This is only possible problem I can think of based on the code you've shown.

Customized UINavigationbar in Universal App

I have a Universal App in which I customize my UINavigationBar.
In my iPhone AppDelegate I use this to achieve it:
#implementation UINavigationBar (CustomImage)
static NSMutableDictionary *navigationBarImages = NULL;
- (void)initImageDictionary
{
if(navigationBarImages==NULL){
navigationBarImages=[[NSMutableDictionary alloc] init];
}
}
- (void)drawRect:(CGRect)rect
{
NSLog(#"drawing navbar2");
UIImage *imageName=[navigationBarImages objectForKey:[NSValue valueWithNonretainedObject: self]];
if (imageName==nil) {
imageName=[UIImage imageNamed:#"bg_titleBar.png"];
UIImage *image = imageName;
[image drawInRect:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
}
}
- (void)setMyImage:(UIImage*)image
{
[navigationBarImages setObject:image forKey:[NSValue valueWithNonretainedObject: self]];
[self setNeedsDisplay];
}
#end
Now my questions: why does this code get called, although I start the iPad simulator?
And more important it seems to corrupt the UIPopoverController because it looks like this:
http://awesome-apps.com/pic/ok.png
While it should look somehow like this:
http://awesome-apps.com/pic/nok.png
Besides it corrupts more in my App, but this should be it for starters :)
Can anyone help me with this? Have you ever had a similar experience?
So ignore the fact that it gets called when you run in the iPad simulator, because as you'll see in a minute even if you used two different categories (one for iPhone, one for iPad) you'd still have this problem.
Here's why:
You are using a category to override the UINavigationBar behaviour. I assume you know what that means - crucially any and all navigation bars in your app will use your supplied methods in the category.
This can cause problems if you're using standard apple elements that use UINavigationBars - the exact thing you're seeing in the popover controller. What's happening is the UIPopoverController uses a UINavigationBar. But because you've defined a category, the app assumes you want the popover navbar to use that category as well.
So that's why you're seeing your weird behaviour in your pop-over controller.
As long as you use categories you'll have this problem, because you can't selectively tell the system which bars should use your category.
I'd suggest you tell us exactly you're trying to customise in the navbar, because there are other ways to achieve customisation outside of categories.

Sending a message to an object

I'm pretty new to Objective C but things are progressing well. However, I think I'm missing a key concept relating to how objects are created and messaged. I hope someone can help me.
I'm creating an iPhone app that simply creates a MPMusicPlayer, and starts playing a song from the que.
I create the music player (myPlayer) in the AppDelegate like so...
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
// Override point for customization after application launch.
// Add the main view controller's view to the window and display.
[window addSubview:mainViewController.view];
[window makeKeyAndVisible];
// instantiate a music player
MPMusicPlayerController *myPlayer =
[MPMusicPlayerController applicationMusicPlayer];
// assign a playback queue containing all media items on the device
[myPlayer setQueueWithQuery: [MPMediaQuery songsQuery]];
// start playing from the beginning of the queue
[myPlayer play];
return YES;
}
This works fine. Now in the MainViewController I try to send myPlayer the command to skip to the next track
[myPlayer skipToNextItem];
However when I try to compile I get the message that myPlayer in undeclared.
What am I doing wrong? I can see how I could fix this in a procedural way (by creating the player in the MainViewController), but I'd like to understand what I have to do to get it working in and OOP way.
Cheers,
Richard
Most propably, the mPlayer object is unknown to your ViewController. There are two options for you:
Make the mPlayer a property of your app delegate
Make the mPlayer a property of your view controller subclass and set it to your mPlayer upon creation
In your appdelegates declaration, do:
#property(nonatomic, retain) MPMusicPlayerController *mPlayer;
In your appdelegates implementation, do:
#synthesize mPlayer;
In your viewcontroller, do:
MPMusicPlayerController *mPlayer = [[[UIApplication sharedApplication] delegate] mPlayer];