まず始めに、私は Objective-C でのプログラミングの初心者 (約 2.5 週間) であり、OS X ココア アプリのコードを書くのはさらに初心者です。IBOutlet プロパティが別のクラスに存在する AppDelegate.m で NSTextField ラベルの値を設定しようとしています。- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{}
MainMenu.xib ファイルが読み込まれて画面に表示される前に NSTextField の値が設定されるように、これを AppDelegate.mのセクションに配置しようとしています。ここに私がこれまでに持っている次のコードがあります:
AppDelegate.m:
#import "AppDelegate.h"
@implementation AppDelegate
- (void)applicationDidFinishLaunching:(NSNotification *)aNotification{
// Get Physical memory in MB
MemoryMonitoring *physicalMemoryObj = [[MemoryMonitoring alloc]init];
unsigned long long physicalMemoryValue = [physicalMemoryObj getPhysicalMemoryValue];
// Set the labels on the slider
RamdiskSize *sizeLabels = [[RamdiskSize alloc]init];
NSString *maxValue = [[NSString alloc] initWithFormat:@"%lluGB",(physicalMemoryValue / 1024)];
// This line is not doing what I had expected
[sizeLabels.textLabelSizeMax setStringValue:maxValue];
}
@end
MemoryMonitoring.h:
#import <Foundation/Foundation.h>
@interface MemoryMonitoring : NSObject
-(unsigned long long)getPhysicalMemoryValue;
@end
MemoryMonitoring.m:
#import "MemoryMonitoring.h"
@implementation MemoryMonitoring
-(unsigned long long)getPhysicalMemoryValue{
NSProcessInfo *pinfo = [NSProcessInfo processInfo];
return ([pinfo physicalMemory] /1024/1024);
}
@end
RamdiskSize.h:
#import <Foundation/Foundation.h>
@interface RamdiskSize : NSObject
@property (weak) IBOutlet NSTextField *textLabelSizeMax;
@end
RamdiskSize.m:
#import "RamdiskSize.h"
#import "MemoryMonitoring.h"
@implementation RamdiskSize
@synthesize textLabelSizeMax;
@end
私の AppDelegate.m でコメントしたように、問題の行は[sizeLabels.textLabelSizeMax setStringValue:maxValue];
. 私の唯一の他のプログラミング経験は VBScript であり、Objective-C がプロパティにアクセスするためにドット構文を使用していると私が知る限り、この行は私が期待していたようには機能していないようです。これがどのように適切に行われるかについて誰かが光を当てることができれば、私はその情報を大いに感謝します.