Sign in to follow this  
taby

iOS touchedEnded not called

Recommended Posts

I started getting this exception thrown by my app: Application windows are expected to have a root view controller at the end of application launch.

 

So I added this code to the didFinishLaunchingWithOptions function:

for(UIWindow *win in windows)
{
    NSLog(@"Window: %@", win.description);
 
    if(win.rootViewController == nil) 
    {
        UIViewController* vc = [[UIViewController alloc]initWithNibName:nil bundle:nil];
        win.rootViewController = vc;
    }
}

Except now, touchesEnded is not called. Do you know why not? It worked fine up until a while ago when the exceptions started happening. If it helps to know, I am using NeHe's iOS Lesson 2 as the base for my app.

 

My touchedEnded code is like such:

- (void) touchesEnded: (NSSet*) touches withEvent: (UIEvent*) event
{
    NSLog(@"TouchesEnded");
    UITouch* touch = [touches anyObject];
    CGPoint location  = [touch locationInView: self];
    lesson->touch_up_pos(location.x, location.y);
}
Edited by sjhalayka

Share this post


Link to post
Share on other sites

Your approach of randomly jamming generic UIViewControllers into every window makes no sense. But to the point, the root view controller you set is the one that receives touchesBegan/Moved/Ended. I don't know where you were receiving those functions previously, and NeHe's lesson 2 is ancient. Can't imagine it's even close to up to date with current iOS practices. From my experience, you should probably just start over with a storyboard based iOS template.

Share this post


Link to post
Share on other sites

I am a fairly long time iOS app builder and Swift is such an amazing and more efficient method of creating apps. There will be some learning curve, and a few things that are not the greatest (in swift 3.0 they removed ++), but the Pros out weight the cons by a vast margin.

I think you will find making new apps more fun and faster.

Share this post


Link to post
Share on other sites

The Nehe iOS code is not really a good starting point.  It was written as an Xcode 4 project We are now on Xcode 8).

The warning you are getting is because your application doesn't have a root view controller because the Nehe code actually just sticks the glview directly as a subview of the window.  This is an old OSX way of doing things and has never been the correct way of doing things in iOS.

The correct fix would be to delete the xib file and create a new one that has a viewController with the glView as its main view.

You would probably be a lot better off just starting from scratch using Swift and GLKit as a starting point and following modern up to date iOS best practices.

 

 

I prefer C++.

 

 

This doesn't make sense as the Nehe code and the code that you have shown is not C++ but, is Objective C.

Share this post


Link to post
Share on other sites

...

 

You can mix C++ code in with Objective C projects. That's how I did my OpenGL ES 2.0 camera, all C++. Right?

 

Thank you for the tip with the xib file. I'll give that a shot.

Edited by sjhalayka

Share this post


Link to post
Share on other sites

 

...

 

You can mix C++ code in with Objective C projects. That's how I did my OpenGL ES 2.0 camera, all C++. Right?

 

Thank you for the tip with the xib file. I'll give that a shot.

 

 

You can mix C++ with Swift also.  Its just a little trickier and you can't do it in the same file.

 

 

 

How do you create a new xib file? I am using Xcode 8.1.

 

 

 

Right click add new file and select "Empty" from the user interface category.  Or you can add a storyboard and do it that way.

 

 

 

In all honesty the Nehe iOS code is Garbage. It was garbage when it was brand new. Its even more worthless now since it doesn't support ARC,  doesn't support any devices newer than iPhone 4s, doesn't use auto-layout, doesn't use modern language features such as auto synthesis, doesn't support cross platform or universal applications,  it uses a timer to do the frame update which has been wrong since around iOS 3, it doesn't manage the application life cycle and as you've just found out doesn't even build using an up to date compiler. You would be much better starting from scratch.
 

File->New->Project
Select Objective C from the language dropdown
Select OpenGL ES from game technology dropdown
Select Universal from the Devices dropdown
Give your project a name
Click Next
Click Create

This will produce the default GLKit starter framework which shows 2 spinning cubes and is already a much better starting point than the Nehe code you are trying to resucitate.  All the gl code is in the GameViewController.m file and you will be able to see a lot of it is similar to the code in the GLView.m from the Nehe version.

Share this post


Link to post
Share on other sites

Thanks for the instructions. I started by using the game template. Two rotating cubes orbiting each other. All I have to do is redo the camera code and shader code. touchesEnded works!

 

I'm still going to try Swift. I got upgraded to Xcode 8.1, which supports Swift 3.

Edited by sjhalayka

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this