未声明的错误和iPhone模拟器崩溃
这是我的密码: h代表未声明的错误和iPhone模拟器崩溃,iphone,Iphone,这是我的密码: h代表 #import <UIKit/UIKit.h> @class _4_Control_FunViewController; @interface _4_Control_FunAppDelegate : NSObject <UIApplicationDelegate> { UIWindow *window; _4_Control_FunViewController *viewController; } @property (nonatomic,
#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
@结束
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
这就是我想要得到的:
这就是我得到的:看起来它“应该”工作,但根据您的屏幕截图,我想说您在Interface Builder中没有正确连接东西
转到Interface Builder并确保它们已连接。如果在头文件中声明了IBOutlet,则需要将其连接到Interface Builder中相应的UI对象
您还有一些冗余代码(如下所示)。它们不会引起问题,但会加倍,因为您在.h文件底部将它们声明为属性。您可以从标题中删除下面的行,但请确保保留相应的@property声明
UIWindow *window;
_4_Control_FunViewController *viewController;
UITextField *nameField;
UITextField *numberField;
您如何才能在应用程序代理的
dealloc
方法中释放nameField
和numberField
。这让我很困惑。我用的是初学者的课本,它已经过时了,而且描述也不是很好。我需要做哪些更改才能使其正常工作?
#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
UIWindow *window;
_4_Control_FunViewController *viewController;
UITextField *nameField;
UITextField *numberField;