6
私は(もちろんのコンストラクタとの完全な)のような、単純な「モデル」クラスを持っているObjective-Cを使ってコントローラ内でカスタムクラス/オブジェクトを初期化する方法
@implementation Widget
@synthesize name;
@synthesize color;
- (id) init
{
if (self = [super init])
{
self.name = @"Default Name";
self.color = @"brown";
}
return self;
}
@end
私はそうのように私のコントローラ内部のメンバーとして、それを宣言した:
#import <UIKit/UIKit.h>
#import "Widget.h"
@interface testerViewController : UIViewController {
IBOutlet UITextField *stuffField;
Widget *widget;
}
@property (nonatomic, retain) UITextField *stuffField;
@property (nonatomic, retain) Widget *widget;
- (IBAction)buttonPressed:(id)sender;
@end
と私のテキストフィールドがアップ空白のたびに来るので、それは私のオブジェクトを初期化していないよう
#import "testerViewController.h"
@implementation testerViewController
@synthesize stuffField;
@synthesize widget;
- (IBAction)buttonPressed:(id)sender
{
stuffField.text = widget.name;
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
if (self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]) {
widget = [[Widget alloc] init];
}
return self;
}
けど..:...私はそうのように私のコントローラ内でそれを初期化しようとしています。すべての手がかりは?
buttonPressed:にブレークポイントを追加し、実際に呼び出されていることを確認します。そこにいる間、widget.nameにマウスを置いてその値を調べることもできます。 – freespace
私は少しでもビジュアルスタジオデバッガに慣れています:(...それは私ですか?または、デバッガのプロパティを横断すると16進数の値ですか? – DaveJustDave