我有一个标签,内容为
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
self.view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"imageName.png"]];
UILabel *testLabel =[[UILabel alloc] initWithFrame:CGRectMake(65,50,200,50)]; // RectMake(xPos,yPos,Max Width I want, is just a container value);
NSString *test=@"I am thinking of a number between 1 and 100. What is it?";
testLabel.font = [UIFont systemFontOfSize:25];
testLabel.textAlignment = NSTextAlignmentCenter;
testLabel.text = test;
testLabel.numberOfLines = 0; //will wrap text in new line
[testLabel sizeToFit];
[self.view addSubview:testLabel];
在这个 ViewController.m 页面的末尾,我在用户提交字段值后按下了一个按钮:
- (IBAction)guessNow:(id)sender {
self.usersGuess = self.guessNumberField.text;
NSString *guessString = self.usersGuess;
if ([guessString length] == 0) {
guessString = @"Really No Guess? Try Again.";
}
//_testLabel.text = @""; attempting to clear out label when user submits the value
NSString *guessReply = [[NSString alloc] initWithFormat:@"Good try but %@ is not the answer!", guessString];
self.testLabel.text = guessReply;
}
问题是当用户在字段中输入值并点击猜测按钮时,答案会显示在初始字段值后面。这是一个屏幕截图:
如何清除初始消息以便只显示回复?