我有在這裏不同類從訪問的NSTextField值的問題是代碼:可可的NSTextField
AppDelegate.h
#import <Cocoa/Cocoa.h>
@interface AppDelegate : NSObject <NSApplicationDelegate>
@property (assign) IBOutlet NSWindow *window;
@property (weak) IBOutlet NSTextField *numberOfPhrases;
@end
AppDelegate.m
#import "AppDelegate.h"
@implementation AppDelegate
@synthesize numberOfPhrases;
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
NSLog(@"%@",[numberOfPhrases stringValue]);
}
TestClass.h
@interface TestClass : NSObject
- (IBAction)doSomething:(id)sender;
@end
TestClass.m
@implementation TestClass
- (IBAction)doSomething:(id)sender {
NSLog(@"%@",[numberOfPhrases stringValue]); ?????????
}
對不起,但我們仍然錯過了點 – crazyjuice
我想從AppDelegate中初始化的textfiled中獲取值。我必須在TestClass中實例化AppDelegate? – crazyjuice
@crazyjuice,錯過這一點會讓代碼不運行 - 如果你有錯誤,在繼續之前需要糾正。 –