这是我的代码: 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
这就是我想要的:
这就是我得到的:
答案 0 :(得分:0)
看起来它“应该”有效,但根据你的截图,我会说你没有在Interface Builder中正确连接。
转到Interface Builder并确保它们已连接。如果您在头文件中声明了IBOutlet,则需要将其连接到Interface Builder中的相应UI对象。
您还有一些冗余代码(如下所示)。它们不会引起问题,但它们会加倍,因为你将它们声明为.h文件底部的属性。您可以从标题中删除下面的行,但请确保保留相应的@property声明。
UIWindow *window;
_4_Control_FunViewController *viewController;
UITextField *nameField;
UITextField *numberField;