Objective c 为什么我不能为UILabel设置文本属性?
我已清除视图控制器中的Objective c 为什么我不能为UILabel设置文本属性?,objective-c,ios,cocoa-touch,Objective C,Ios,Cocoa Touch,我已清除视图控制器中的ui标签 @interface ViewController : UIViewController { UILabel *statusText; } @property (nonatomic,retain) IBOutlet UILabel *statusText; -(IBAction)buttonPressed:(id)sender; @end 现在我想在按下按钮时更改ui标签的标题,但是我的statusText无法正确设置标题。例如: - (IBActio
ui标签
@interface ViewController : UIViewController
{
UILabel *statusText;
}
@property (nonatomic,retain) IBOutlet UILabel *statusText;
-(IBAction)buttonPressed:(id)sender;
@end
现在我想在按下按钮时更改ui标签的标题,但是我的statusText
无法正确设置标题。例如:
- (IBAction)buttonPressed:(id)sender{
NSString *title = [sender titleForState:UIControlStateNormal];
NSString *newText = [[NSString alloc]initWithFormat:@"%@button pressed",title];
statusText.text = @"helloworld";
NSLog(@"%@",statusText.text);
[newText release];
}
日志返回
2012-01-25 00:46:27.663 buttonfun[34247:f803] (null)
这意味着尚未设置文本属性“helloworld”。为什么?请尝试记录以下内容:
NSLog(@"%@",statusText);
如果该值也为空,则表示您尚未将您的statusText
IBOutlet连接到Interface Builder中的UILabel
(您需要按住ctrl键将文件所有者拖动到标签上,然后选择statusText
)。尝试将其记录下来:
NSLog(@"%@",statusText);
如果它也为空,则表示您尚未将statusText
IBOutlet连接到Interface Builder中的UILabel
(您需要按住ctrl键将文件所有者拖动到标签上,然后选择statusText
).您的IBOutlet是否在Interface Builder中正确连接?您是否合成了UILabel?您的IBOutlet是否在Interface Builder中正确连接?您是否合成了UILabel?