【问题标题】:Refreshing UILabel刷新UILabel
【发布时间】:2011-06-14 04:16:22
【问题描述】:

我有一个 IBAction,可以将某些按钮上的按下内容显示到 UILabel。我有另一个用于 equalPressed 按钮的 IBAction,它可以做很多事情,但我还添加了 titleDisplay.text = nil;它第一次完美运行。然后在我按下 equalPressed 按钮后,它不会出现。我知道这是因为我将 titleDisplay.text 设置为 nil。但是,我不知道如何使用 equalPressed 按钮清除 UILabel,以便我的其他按钮可以显示在屏幕上而无需不断附加

第一个 IBA 操作

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

第二次IBA操作

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

【问题讨论】:

    标签: iphone objective-c


    【解决方案1】:

    第一次起作用的原因是,当您将nil 分配给一个对象时,您实际上是在转储您对它的引用。您应该将文本设置为空字符串,如下所示:

    [titleDisplay setText:@""];
    

    【讨论】:

    • 谢谢,我完全忽略了显而易见的事情。
    【解决方案2】:

    试试

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

    【讨论】:

    • 非常感谢。我真的觉得自己很白痴,我只是一直忽视显而易见的事情。再次真诚地感谢。
    猜你喜欢
    • 1970-01-01
    • 2019-02-01
    • 1970-01-01
    • 2018-08-28
    • 1970-01-01
    • 1970-01-01
    • 2018-05-25
    • 2018-11-11
    • 1970-01-01
    相关资源
    最近更新 更多