主要思路:基本MVC:設置變量的NSTextField輸入不同類別
型號:從textfield
值設置爲我可以調用/日誌的變量。
查看:只是一個NSTextField
迷上了Model
類。
控制器:NSButton
迷上了ViewController
。
正如您會注意到的那樣,它記錄了NSLog的基本字符串,也是預定義的begin
值。但當我要求的txtBegin
價值它返回NULL
我知道TextField
和Button
掛鉤在連接檢查。
截圖:
ViewController.h
#import <Cocoa/Cocoa.h>
#import "Model.h"
@interface ViewController : NSView
- (IBAction)logTheVariable:(id)sender;
@end
ViewController.m
- (IBAction)logTheVariable:(id)sender
{
Model *myModel = [[Model alloc]init];
[myModel doSomething];
}
Model.h
#import <Foundation/Foundation.h>
@interface Model : NSObject{
//iVars
int begin;
}
//properties
@property (weak) IBOutlet NSTextField *txtBegin;
//methods
-(void)doSomething;
@end
Model.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
沒有工作,我還是謝謝你! –