简体   繁体   English

未声明的错误和 iPhone 模拟器崩溃

[英]Undeclared Error and iPhone Simulator Crashing

Here's my code: delegate.h这是我的代码: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:代表.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视图控制器.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视图控制器.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.看起来它“应该”工作,但根据您的屏幕截图,我会说您在 Interface Builder 中没有正确连接东西。

Go to Interface Builder and make sure they are hooked up. Go 到 Interface Builder 并确保它们已连接。 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.如果您在 header 文件中声明了 IBOutlet,则需要将其连接到 Interface Builder 中相应的 UI object。

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.它们不会引起问题,但它们会加倍,因为您在 your.h 文件的底部将它们声明为属性。 You can delete the lines below from your headers, but make sure you leave their corresponding @property declarations in place.您可以从标题中删除以下行,但请确保保留它们相应的 @property 声明。

UIWindow *window;
_4_Control_FunViewController *viewController;

UITextField *nameField;
UITextField *numberField;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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