试图将默认值传递给 ViewController 对象的实例。代码在没有警告的情况下编译,我逐步查看设置的值,但是,当应用程序启动时,UI 上的值又归零。就好像我正在创建两个不同的实例,但对于我的一生来说,我无法理解为什么初始化值不是已启动应用程序的一部分。这是实现和 main.m 代码。任何帮助表示赞赏。
#import "AppDelegate.h"
#import <UIKit/UIKit.h>
#import "ViewController.h"
int main(int argc, char *argv[]) {
//NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
@autoreleasepool {
ViewController *viewController;
viewController = [[ViewController alloc]initWithBinauralFrequencyLeft:82.4
binauralFreqRight:82.4
octaveValue:1
baseScaleSetting:82.4
binauralBaseVolume:800
globalBaseSongCount:0];
int retVal = UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
//[pool release];
return retVal;
}
}
-(id)initWithBinauralFrequencyLeft:(double)binauralFreqL
binauralFreqRight:(double)binauralFreqR
octaveValue:(double)octaveVal
baseScaleSetting:(double)baseScaleSet
binauralBaseVolume:(int)binauralVolume
globalBaseSongCount:(int)globalSongCount;
{
self = [super init];
if (self){
[self setBinauralFreqL:82.4];
[self setBinauralFreqR:82.4];
[self setOctaveVal:1];
[self setBaseScaleSet:82.4];
[self setBinauralVolume:800];
[self setGlobalSongCount:0];
}
return self;
}
-(id)init
{
return [self initWithBinauralFrequencyLeft:82.4 binauralFreqRight:82.4 octaveValue:1 baseScaleSetting:82.4 binauralBaseVolume:800 globalBaseSongCount:0];
}