Devin Wenzel
Devin Wenzel

Reputation: 15

Refreshing UILabel

I have an IBAction that displays what is being pressed on certain buttons to a UILabel. I have another IBAction for equalPressed button that does many things, but I also added titleDisplay.text = nil; It works perfectly the first time. Then after I press the equalPressed button it doesn't show up. I know it is because i have titleDisplay.text set to nil. However, I don't know how to clear the UILabel with the equalPressed button so my other buttons can be displayed on the screen without appending constantly

First IBAction

- (IBAction) titleLabel: (UIButton *) sender {
    NSString *titleOfButton = [[sender titleLabel] text]; 
    titleDisplay.text = [[titleDisplay text] stringByAppendingString: titleOfButton]; 
}

Second IBAction

- (IBAction) equalPressed: (UIButton *) sender {
    titleDisplay.text = nil; 
}

Upvotes: 0

Views: 173

Answers (2)

Moshe
Moshe

Reputation: 58067

The reason why this would work only the first time is because when you assign nil to an object, you're essentially dumping your reference to it. You should instead set the text to an empty string, like so:

[titleDisplay setText:@""];

Upvotes: 2

Vladimir
Vladimir

Reputation: 170829

Try

- (IBAction) equalPressed: (UIButton *) sender {
    titleDisplay.text = @""; 
}

Upvotes: 1

Related Questions