我有一個類RandomGenerator:值設置爲忽略的NSTextField
// RandomGenerator.h
#import <Foundation/Foundation.h>
@interface RandomGenerator : NSObject
{
@private
IBOutlet NSTextField* textField;
unsigned int number;
}
@end
//RandomGenerator.m
#import "RandomGenerator.h"
@implementation RandomGenerator
- (id)init
{
self = [super init];
if (self)
{
textField=[[NSTextField alloc]init];
[textField setStringValue:@"Insert a number between 1 and 100"];
srand((unsigned int)time(NULL));
}
return self;
}
- (void)dealloc
{
[super dealloc];
}
@end
所構建時,它將自動設置的NSTextField的值。 我從文件GuessTheNumberAppDelegate.m分配RandomGenerator對象:
#import "GuessTheNumberAppDelegate.h"
#import "RandomGenerator.h"
@implementation GuessTheNumberAppDelegate
@synthesize window;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSAutoreleasePool* pool=[[NSAutoreleasePool alloc]init];
RandomGenerator* random=[[RandomGenerator alloc]init];
[pool drain];
}
@end
而且我已在界面生成器連接:
不過的NSTextField的含量沒有改變,看起來是一樣的,爲什麼呢?
這幫助了很多,謝謝。 – 2012-02-26 22:44:04