简体   繁体   中英

Undeclared Error and iPhone Simulator Crashing

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];
[nameField 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:这里。

This is what I'm getting:这里。

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM