1秒に1回、時計の読み取り値をUIButton
のラベルとして表示します。しかし、私はsuperView
新しいUIButton
からそれを削除するにもかかわらず、この のように、古いものを上書きし...と、この数分後に私のiPhoneは、私の
NSTimer
方法は次のようになりPlayViewController
で真剣に焼けた:-)ボタンを再描画せずにUIButtonのラベルを更新できますか?
を見て
- (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;
私の質問は:私は、ボタンを再描画することなく、UIButton
ラベルを更新することができますか?これはdelegate
を使用して解決できる問題ですか? delegates
(例えば以下)ViewController
へUIButton
からメッセージを送信するためにされている使用して、私の経験をこれまでに
しかし、これまで私は、メッセージが反対方向に送信される場合に適用することができる午前例を発見していません。したがって、delegate
を推奨する方法を使用している場合は、この問題を解決するのに役立ついくつかのコードを教えてください。おかげ
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
EscButton.m
#import "EscButton.h"
@implementation EscButton
- (id)loadEscButton:(NSString *)text {
CGFloat sideOffset = screenWidth - ESC_BUTTON_Width - MARGIN_Side;
CGFloat topOffset = statusBarHeight + MARGIN_Top;
UIButton *escButton = [UIButton buttonWithType:UIButtonTypeCustom];
escButton.frame = CGRectMake(sideOffset, topOffset, ESC_BUTTON_Width, ESC_BUTTON_Height);
// etc …
[escButton addTarget:self.delegate action:@selector(fromEscButton:) forControlEvents:UIControlEventTouchUpInside];
[escButton setTitle:text forState:UIControlStateNormal];
// etc …
return escButton;
}
@end
はあなたが意味するか
に次のコードを変更して、[self.viewのaddSubviewを:secondsB] ; ? – Greg
RunLoop、これは私がコメントした行を変更したときに私の問題を解決しました。私はあなたの答えに行くよ。 – Greg
ありがとうございました - ごめんなさい、今は誤植です。 – RunLoop