开发者

Undeclared Error and iPhone Simulator Crashing

开发者 https://www.devze.com 2023-03-10 16:43 出处:网络
Here\'s my code: delegate.h #import <UIKit/UIKit.h> @class _4_Control_FunViewController; @interface _4_Control_FunAppDelegate : NSObject <UIApplicationDelegate> {

Here's my code: delegate.h

#import <UIKit/UIKit.h>

@class _4_Control_FunViewController;

@interface _4_Control_FunAppDelegate : NSObject <UIApplicationDelegate> {
UIWindow *window;
_4_Control_FunViewController *viewController;
}

@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet _4_Control_FunViewController *viewController;

@end

delegate.m:

#import "_4_Control_FunAppDelegate.h"
#import "_4_Control_FunViewController.h"

@implementation _4_Control_FunAppDelegate

@synthesize window;
@synthesize viewController;


#pragma mark -
#pragma mark Application lifecycle

 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:    (NSDictionary *)launchOptions {    

[window addSubview:viewController.view];
[window makeKeyAndVisible];

return YES;
}


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

}


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

}


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

}


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

}


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

}


#pragma mark -
#pragma mark Memory management

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

}


- (void)dealloc {
[viewController release];
[window release];
[nameF开发者_JAVA技巧ield release];
[numberField release];
[super dealloc];
}

@end

ViewController.h

#import <UIKit/UIKit.h>

@interface _4_Control_FunViewController : UIViewController {
UITextField *nameField;
UITextField *numberField;
}
@property (nonatomic, retain) IBOutlet UITextField *nameField;
@property (nonatomic, retain) IBOutlet UITextField *numberField;
@end

ViewController.m

#import "_4_Control_FunViewController.h"

@implementation _4_Control_FunViewController
@synthesize nameField;
@synthesize numberField;


- (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

This is what I'm trying to get:

Undeclared Error and iPhone Simulator Crashing

This is what I'm getting:

Undeclared Error and iPhone Simulator Crashing


Looks like it "should" work, but based on your screenshot, I'd say you haven't got things connected correctly in Interface Builder.

Go to Interface Builder and make sure they are hooked up. Where ever you have an IBOutlet declared in a header file, that needs to be hooked up to the corresponding UI object in Interface Builder.

You also have some redundant code (shown below). They are not causing problems, but they double up because you have them declared as properties at the bottom your .h file. You can delete the lines below from your headers, but make sure you leave their corresponding @property declarations in place.

UIWindow *window;
_4_Control_FunViewController *viewController;

UITextField *nameField;
UITextField *numberField;
0

精彩评论

暂无评论...
验证码 换一张
取 消