Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Mockup & CodeGen, iPhone & iPad
($9.99)

Make your own iPhone apps
and run them live!
(free)

Manu
($0.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-14-2009, 04:39 AM   #1 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default Unable to link my OpenGL app with the iPhone interface!

Hi there!

I'm trying to integrate the iPhone Interface (a UITextField in my case) to and OpenGL app I've done (everything's almost done, but the name entry system for the scores) but I'm unable to do such that (I suppose) trivial thing!
I've never developed using the iPhone Interface (always worked in OpenGL) and I've followed the Apple's iPhone Dev Center Tutorial for the iPhone SDK (a "Hello world" with a UITextField -bingo!-, a UILabel and a UIButton). In the tutorial, as always, everything looks easy, intuitive (more or less), and everything worked well. But, back to real life, integrating my existing app with the Interface is not as trivial as I hoped to be...
I have an OGLGameAppDelegate, a EAGLView, and I've created a myViewController class (where I want to add the UITextField). I don't know if this last class is necessary or if I can use the EAGLView class to add the UITextField, but the EAGLView hasn't got a NIB file, so I've decided creating a new "layer" to add there the Interface elements.
What I have in the OGLGameAppDelegate and in the myViewController is:

************************************************** **********
// OGLGameAppDelegate.h
#import <UIKit/UIKit.h>

@class EAGLView;
@class MyViewController;

@interface OGLGameAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
EAGLView *glView;
MyViewController *myViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet EAGLView *glView;
@property (nonatomic, retain) MyViewController *myViewController;

@end
--------------------------------------------------------------------------------
// OGLGameAppDelegate.m
#import "OGLGameAppDelegate.h"
#import "EAGLView.h"
#import "MyViewController.h"

@implementation OGLGameAppDelegate

@synthesize window;
@synthesize glView;
@synthesize myViewController;

- (void)applicationDidFinishLaunching: (UIApplication * )application {

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];

MyViewController *aViewController = [[MyViewController alloc]
initWithNibName:@"MyViewController" bundle: [NSBundle mainBundle]];
[self setMyViewController:aViewController];
// Tambe podria ser --> self.myViewController = aViewController;
[aViewController release];

glView.animationInterval = 1.0 / 60.0;
[glView startAnimation];
}


- (void)applicationWillResignActive: (UIApplication *)application {
glView.animationInterval = 1.0 / 5.0;
}


- (void)applicationDidBecomeActive: (UIApplication *)application {
glView.animationInterval = 1.0 / 60.0;
}

- (void)applicationDidReceiveMemoryWarning: (UIApplication *)application {
NSLog(@"***** MEMORY WARNING *****");
[glView warning];
//[glView alliberaMemoria];
}


- (void)dealloc {
[myViewController release];

[window release];
[glView release];
[super dealloc];
}

@end

--------------------------------------------------------------------------------
// myViewController.h
#import <UIKit/UIKit.h>


@interface myViewController : UIViewController <UITextFieldDelegate> {
UITextField *textField;
}

@property (nonatomic, retain) IBOutlet UITextField *textField;

@end
--------------------------------------------------------------------------------
// myViewController.m
#import "myViewController.h"


@implementation myViewController

@synthesize textField;

- (BOOL)textFieldShouldReturn:(UITextField *)theTextField {
if (theTextField == textField) {
[textField resignFirstResponder];
}
return YES;
}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
[super dealloc];
}


@end
************************************************** **********

And, in the myViewController.xib file, I've created a UITextField named "textField", linked it's "delegate" to "File's Owner" (which is of myViewController class), linked it's "textField" to "File's Owner", and linked the File's Owner "textField" to "textField", the "view" to "View", and the "delegate" to "textField".
I don't know exactly how it works, but I've done the same I've done with the "Hello world" example...

However, when I try to compile, XCode gives me an error:
************************************************** **********
Link /Volumes/(...)
".objc_class_name_MyViewController", referenced from:
Literal-pointer@__OBJC@__cls_refs@MyViewController in OGLGameAppDelegate.o
Symbol(s) not found
Collect2: Id returned 1 exit status
************************************************** **********

Can anyone help me with this? It's getting me mad as seconds pass...

Thanks in advance! :)
Johanovski is offline   Reply With Quote
Old 12-14-2009, 06:46 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 291
Send a message via Yahoo to iphonegamedeveloper
Default

Quote:
Originally Posted by Johanovski View Post
Hi there!

I'm trying to integrate the iPhone Interface (a UITextField in my case) to and OpenGL app I've done (everything's almost done, but the name entry system for the scores) but I'm unable to do such that (I suppose) trivial thing!
I've never developed using the iPhone Interface (always worked in OpenGL) and I've followed the Apple's iPhone Dev Center Tutorial for the iPhone SDK (a "Hello world" with a UITextField -bingo!-, a UILabel and a UIButton). In the tutorial, as always, everything looks easy, intuitive (more or less), and everything worked well. But, back to real life, integrating my existing app with the Interface is not as trivial as I hoped to be...
I have an OGLGameAppDelegate, a EAGLView, and I've created a myViewController class (where I want to add the UITextField). I don't know if this last class is necessary or if I can use the EAGLView class to add the UITextField, but the EAGLView hasn't got a NIB file, so I've decided creating a new "layer" to add there the Interface elements.
What I have in the OGLGameAppDelegate and in the myViewController is:

************************************************** **********
// OGLGameAppDelegate.h
#import <UIKit/UIKit.h>

@class EAGLView;
@class MyViewController;

@interface OGLGameAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
EAGLView *glView;
MyViewController *myViewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet EAGLView *glView;
@property (nonatomic, retain) MyViewController *myViewController;

@end
--------------------------------------------------------------------------------
// OGLGameAppDelegate.m
#import "OGLGameAppDelegate.h"
#import "EAGLView.h"
#import "MyViewController.h"

@implementation OGLGameAppDelegate

@synthesize window;
@synthesize glView;
@synthesize myViewController;

- (void)applicationDidFinishLaunching: (UIApplication * )application {

[[UIApplication sharedApplication] setStatusBarHidden:YES animated:NO];

MyViewController *aViewController = [[MyViewController alloc]
initWithNibName:@"MyViewController" bundle: [NSBundle mainBundle]];
[self setMyViewController:aViewController];
// Tambe podria ser --> self.myViewController = aViewController;
[aViewController release];

glView.animationInterval = 1.0 / 60.0;
[glView startAnimation];
}


- (void)applicationWillResignActive: (UIApplication *)application {
glView.animationInterval = 1.0 / 5.0;
}


- (void)applicationDidBecomeActive: (UIApplication *)application {
glView.animationInterval = 1.0 / 60.0;
}

- (void)applicationDidReceiveMemoryWarning: (UIApplication *)application {
NSLog(@"***** MEMORY WARNING *****");
[glView warning];
//[glView alliberaMemoria];
}


- (void)dealloc {
[myViewController release];

[window release];
[glView release];
[super dealloc];
}

@end

--------------------------------------------------------------------------------
// myViewController.h
#import <UIKit/UIKit.h>


@interface myViewController : UIViewController <UITextFieldDelegate> {
UITextField *textField;
}

@property (nonatomic, retain) IBOutlet UITextField *textField;

@end
--------------------------------------------------------------------------------
// myViewController.m
#import "myViewController.h"


@implementation myViewController

@synthesize textField;

- (BOOL)textFieldShouldReturnUITextField *)theTextField {
if (theTextField == textField) {
[textField resignFirstResponder];
}
return YES;
}

- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];

// Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}


- (void)dealloc {
[super dealloc];
}


@end
************************************************** **********

And, in the myViewController.xib file, I've created a UITextField named "textField", linked it's "delegate" to "File's Owner" (which is of myViewController class), linked it's "textField" to "File's Owner", and linked the File's Owner "textField" to "textField", the "view" to "View", and the "delegate" to "textField".
I don't know exactly how it works, but I've done the same I've done with the "Hello world" example...

However, when I try to compile, XCode gives me an error:
************************************************** **********
Link /Volumes/(...)
".objc_class_name_MyViewController", referenced from:
Literal-pointer@__OBJC@__cls_refs@MyViewController in OGLGameAppDelegate.o
Symbol(s) not found
Collect2: Id returned 1 exit status
************************************************** **********

Can anyone help me with this? It's getting me mad as seconds pass...

Thanks in advance!


check the user interaction enable option in view in interface builder
iphonegamedeveloper is offline   Reply With Quote
Old 12-14-2009, 07:05 AM   #3 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default

Hi!

It's enabled and nothing's running yet... Don't know where I have to place the UITextField, or where I have to link, or if life is fair, and a large etcetera...

But thanks for your response!
Johanovski is offline   Reply With Quote
Old 12-14-2009, 07:10 AM   #4 (permalink)
Registered Member
 
Join Date: Jul 2009
Posts: 291
Send a message via Yahoo to iphonegamedeveloper
Default

Quote:
Originally Posted by Johanovski View Post
Hi!

It's enabled and nothing's running yet... Don't know where I have to place the UITextField, or where I have to link, or if life is fair, and a large etcetera...

But thanks for your response!
if you are using interface builder

Did you connect textfield using inspecter..

or if u are doing with view..

did you addlike this


[yourviewname addsubview:textfieldname];

ex:[glview addsubview:username];

add it once in your program
iphonegamedeveloper is offline   Reply With Quote
Old 12-14-2009, 07:15 AM   #5 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: London
Posts: 226
Default

A couple of quick suggestions. Don't know if they'll help.

1) Check that the MyViewController files are marked for inclusion in the project. Select MyViewController.m in "Groups & Files" on the left, and then look at the file list above the main editor. There should be a tick in the right-most column, under the little target icon.

2) Try cleaning the project (Build menu -> Clean all targets) and then building again.
__________________
SimCap - Simple iPhone and iPad Simulator screen capture
_sjc_ is offline   Reply With Quote
Old 12-14-2009, 07:35 AM   #6 (permalink)
Registered Member
 
Join Date: Nov 2009
Location: London
Posts: 226
Default

As far as adding the text field goes, I think adding an entire new view controller is probably the wrong way to go. You should be able to manage the whole process from the EAGLView -- since this is where most of your logic probably is, including whichever code tracks the games current state.

Since I don't know all the details of your project, this is really just a "thinking aloud" list of suggestions.

* Views are displayed in hierarchies. Your EAGLView is just another view in this respect. You'll probably want to add the UITextField as a subview under it. (You'll notice a degradation in performance when you do, but I'm guessing you won't be wanting to do much else while the user is entering their score.)

* Adding just the UITextFieldDelegate methods needed to the EAGLView controller shouldn't add much bloat to the code. You may only need to implement textFieldShouldReturn: and textFieldDidEndEditing:.

* So you'll need a "getPlayerName" method to create the textField, add it as a subview, and make it first responder (which makes the keyboard appear); an implementation of textFieldShouldReturn: to check the player entered something and if so, get the textfield to resign first responder (which dismisses the keyboard); and an implementation textFieldDidEndEditing: to remove and destroy the textfield and do something with the input.

Like I said, this is just a rough outline of the approach I would take.
__________________
SimCap - Simple iPhone and iPad Simulator screen capture
_sjc_ is offline   Reply With Quote
Old 12-14-2009, 09:49 AM   #7 (permalink)
Divine avenger
 
Johanovski's Avatar
 
Join Date: Nov 2009
Location: Vic, Catalunya (Spain)
Posts: 320
Default

GOD BLESS YOU _sjc_! It works! ^_^

Thanks, I'm getting really ill with this and the damned Interface Builder with it's delegates, connections, and other strange properties like File's Owner, views, the Easter Bunny and it's eggs!

Thanks!

PD: I'll make you a gold statue!
Johanovski is offline   Reply With Quote
Reply

Bookmarks

Tags
eaglview, interface builder, myviewcontroller, uitextfield

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 270
22 members and 248 guests
ADY, AragornSG, Bertrand21, Dani77, Dattee, fkmtc, HDshot, iDifferent, jakerocheleau, JasonR, jimbo, macquitzon216, mer10, prchn4christ, Rudy, sacha1996, silverwiz, sneaky, spiderguy84, Sunny46, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,767
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 03:07 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0