【发布时间】:2012-07-28 06:27:03
【问题描述】:
代码来自斯坦福 CS193p。我添加了一个 NSLog 来检查它。标签似乎没有被初始化。有什么想法吗?
@interface AskerViewController() <UITextFieldDelegate>
@property (weak, nonatomic) IBOutlet UILabel *questionLabel;
@property (weak, nonatomic) NSString *question;
@end
@implementation AskerViewController
@synthesize questionLabel = _questionLabel;
@synthesize question = _question;
- (void)setQuestion:(NSString *)question
{
_question = question;
self.questionLabel.text = question;
NSLog(@"label is %@", self.questionLabel);
}
@end
NSLog 结果是:
2012-07-31 01:56:45.177 Kitchen Sink[23931:f803] label is (null)
【问题讨论】:
-
什么的getter和setter?他们在接到电话时会接到电话,您需要提供更多信息,否则无法回答此问题。
-
你是对的。我修改了帖子并添加了代码以使问题具体化。
-
您的 UILabel 是否已连接/链接到 questionLabel?
-
setQuestion:不初始化标签。它只设置文本。标签是否已初始化?在 Interface Builder 中是否连接了插座? -
肯定,questionLabel通过storyboard连接到控制器
标签: ios objective-c setter init cs193p