主要思想:
模型:将值设置为textfield
我可以调用/记录的变量。
观点:只是一个NSTextField
迷上了Model
班级。
控制器:NSButton
连接到ViewController
.
你会注意到,它记录了来自 NSLog 的基本字符串,也是预定义的begin
值。但是当我要求txtBegin
它返回的值时NULL
我知道TextField
和Button
连接在连接检查器中。
截屏:
视图控制器.h
#import <Cocoa/Cocoa.h>
#import "Model.h"
@interface ViewController : NSView
- (IBAction)logTheVariable:(id)sender;
@end
视图控制器.m
- (IBAction)logTheVariable:(id)sender
{
Model *myModel = [[Model alloc]init];
[myModel doSomething];
}
模型.h
#import <Foundation/Foundation.h>
@interface Model : NSObject{
//iVars
int begin;
}
//properties
@property (weak) IBOutlet NSTextField *txtBegin;
//methods
-(void)doSomething;
@end
模型.m
#import "Model.h"
@implementation Model
-(void)doSomething{
NSLog(@"I'm in the Model Class"); //logs like a charm!
begin = 5; //just a test to see if it logs anything (which works)
NSLog(@"%d",begin);// logs like a charm!
//->Problem is here <-
NSLog(@"%@",_txtBegin.stringValue); //returns a "NULL" value.
//->Problem is here <-
}
@end