我有一个像这样的简单"模型"类(当然还有构造函数)
@implementation Widget @synthesize name; @synthesize color; - (id) init { if (self = [super init]) { self.name = @"Default Name"; self.color = @"brown"; } return self; } @end
我已经将它声明为我的控制器的内部成员,如下所示:
#import#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; }
但是......它似乎没有初始化我的对象,因为我的文本字段每次都显示为空白.有线索吗?