开发者

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] stringByAppending开发者_如何学PythonString: titleOfButton]; 
}

Second IBAction

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


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:@""];


Try

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜