CocosCreator Label组件无法赋值的问题

我的问题是这样的,为Label.string赋值。但是赋不上,界面不刷新。Log打印的是有值的。

export default class DoubleCoinPage extends cc.Component {

    @property(cc.Node)
    close: cc.Node = null;
    @property(cc.Node)
    watchVideo: cc.Node = null;
    @property(cc.Node)
    timeLabel: cc.Label = null;

    public Show() {
        this.close.addComponent(TouchComp).SetTouchEndCallback(this.onCloseClicked.bind(this));
        this.watchVideo.addComponent(TouchComp).SetTouchEndCallback(this.onWatchVideoClicked.bind(this));

        NotificationCenter.Instance.on(NotificationType.DoubleCoinLeftTimeChange, this.onLeftTimeChange, this);

    }
    private onCloseClicked(event: cc.Event.EventTouch) {
        NotificationCenter.Instance.off(NotificationType.DoubleCoinLeftTimeChange, this.onLeftTimeChange, this);
        PageManager.Instance.HideDoubleCoinPage();
    }
    private onWatchVideoClicked(event: cc.Event.EventTouch) {
        //TODO:在视频播放完成后的回调中增加时间
        DataManager.Instance.DoubleCoinLeftTime = DataManager.Instance.DoubleCoinLeftTime + 300;
    }

    private onLeftTimeChange(value: number) {
        let str = NumberExt.ToHMS(value);
        Debug.Error("onLeftTimeChange:" + value + ", str:" + str);
        this.timeLabel.string = str;
        Debug.Error("@@@:" + this.timeLabel.string);
    }
}

如上代码,log打印了str字符串值是对的。打印的this.timeLabel.string的值也是对的。但是在UI层,并没有刷新。

看看Label组件下面的Batch As Bitmap 这个勾是不是挑上了,去掉应该就可以。

大佬,没得这个选项哦。

如果有调用方法,但是赋值失败就是this的问题

是不是你timeLabel property中的type是cc.Node的缘故啊

这种情况我也遇到过,找不到原因,我就把label换成富文本就可以显示了:scream:

快一点的方法就是,你先试试其他label是否也有同样的情形,如果是,再开一个demo专案是否也是这样的情时,如果是! 就发上来看看吧