Objective c 我可以在不重新绘制按钮的情况下更新UIButton中的标签吗?

Objective c 我可以在不重新绘制按钮的情况下更新UIButton中的标签吗?,objective-c,uiview,uibutton,delegates,nstimer,Objective C,Uiview,Uibutton,Delegates,Nstimer,我希望时钟读数每秒以标签形式出现在ui按钮中一次。但是,即使我将其从超级视图中删除,新的ui按钮也会覆盖旧按钮,如下所示 …几分钟后,我的iPhone看起来严重烧坏了:-) 在PlayViewControllermyNSTimer中,方法如下所示 - (void)startClock { clockCount = 0; // start on 1st clock pulse totalMinutes =

我希望时钟读数每秒以标签形式出现在
ui按钮中一次。但是,即使我将其从
超级视图中删除,新的
ui按钮也会覆盖旧按钮,如下所示
…几分钟后,我的iPhone看起来严重烧坏了:-)

PlayViewController
my
NSTimer
中,方法如下所示

    - (void)startClock {    
        clockCount         =  0;       // start on 1st clock pulse
        totalMinutes       =  0;        // appears on clockButton
        totalSeconds       =  0;        // appears on clockButton

        timer = [NSTimer scheduledTimerWithTimeInterval:STATES_ConcertClock
                                             target:self
                                           selector:@selector(nextClock)
                                           userInfo:nil
                                            repeats:YES];
    }

    - (void)nextClock {

        self.lastEventChangeTime = [NSDate date];    
        clockCount++;
        [self masterClockReadout];    
    }
这是我的时钟读出方法

    - (void)masterClockReadout                              {
        totalMinutes       = clockCount / 60;
        totalSeconds       = clockCount % 60;
        clockString        = [NSString stringWithFormat:@"%02d:%02d", totalMinutes, totalSeconds];

        [self.seconds removeFromSuperview];
        EscButton *seconds = [[EscButton alloc] loadEscButton:(NSString *)clockString];
        [self.view addSubview:seconds];
    }
我还设置了一个
UIView
属性,以便
removeFromSuperview
知道要删除什么

    @property (nonatomic, retain) UIView* seconds;
我的问题是:我是否可以在不重新绘制按钮的情况下更新
ui按钮
标签?这是一个可以通过使用
委托解决的问题吗

迄今为止,我使用
代理
的经验是将消息从
ui按钮
发送到
ViewController
(如下图),但到目前为止,我还没有找到一个可以应用于相反方向发送消息的示例。因此,如果建议使用
委托
,请您为我指出一些可能帮助我解决此问题的代码。谢谢

EscButton.h

    #import <UIKit/UIKit.h>

    @protocol EscButtonDelegate <NSObject>
    -(void)fromEscButton:(UIButton*)button;
    @end

    @interface EscButton : UIView {    
    }
    - (id)loadEscButton:(NSString *)text;
    @property (assign) id<EscButtonDelegate> delegate;
    @end

无需不断添加和删除按钮。你可以保留同一个。更改以下代码:

@property (nonatomic, retain) UIView* seconds;
致:

也改变了:

[self.seconds removeFromSuperview];
EscButton *seconds = [[EscButton alloc] loadEscButton:(NSString *)clockString];
[self.view addSubview:seconds];
致:


你是说[self.view addSubview:secondsB]?RunLoop,这解决了我在更改我评论的行时的问题。我同意你的回答。
@property (nonatomic, retain) UIButton *secondsB;
[self.seconds removeFromSuperview];
EscButton *seconds = [[EscButton alloc] loadEscButton:(NSString *)clockString];
[self.view addSubview:seconds];
if (!self.secondsB) {

    self.secondsB = [[EscButton alloc] loadEscButton:(NSString *)clockString];
    [self.view addSubview:_secondsB]; // previously addSubview:seconds]; 
}

[self.secondsB setTitle:clockString forState:UIControlStateNormal];