カスタム クラス Custom.mm があり、コントローラー クラス MainController でセッターを使用して float 値を設定しようとしています。Custom インスタンスは、Obj-C++ ファイルであり、コンパイル時に適切なクラスを指しているため、id として型指定されています。すべて正常に動作し、インスタンスが検証されました。amount 変数を int 型として設定し、int を渡すと、正常に動作します。フロートを除く、他の値またはオブジェクトと同じです。Custom.mm クラスでは、何らかの理由で float (float、CGFloat など) が 0 に設定されています。これは NSLog などの問題ではありません。ブレークポイントを使用して amount 変数をチェックしたところ、すべてが動作しましたが、フロートしました。
//Custom.h
@interface Custom : UIView
{
CGFloat amount;
}
@property CGFloat amount;
@end
//Custom.mm
@implementation Custom
@synthesize amount;
- (id) initWithCoder:(NSCoder*)coder
{
if ((self = [super initWithCoder:coder]))
{
//set initial value to 1
self.amount = 1.0; //verified as 1.0
}
return self;
}
//MainController.h
@interface MainController : UIViewController
{
IBOutlet id customInstance; //IB points to the CustomView class
}
//MainController.m
@implementation MainController
-(void)viewDidLoad
{
[super viewDidLoad];
//Checking this value in Custom.mm via the debugger shows it as being 0,
//when before it was 1.0.
[customInstance setAmount:2.0];
}
@end