From 549106e931962c9d2fc183997e576f07f39750f4 Mon Sep 17 00:00:00 2001 From: Coderzhangsl Date: Thu, 2 Jun 2016 10:38:50 +0800 Subject: [PATCH 1/2] =?UTF-8?q?retain=20circle=20=E5=AF=BC=E8=87=B4timerLa?= =?UTF-8?q?bel=E4=B8=8D=E8=83=BD=E9=87=8A=E6=94=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1 - (UILabel*)timeLabel { if (_timeLabel == nil) { _timeLabel = self; } return _timeLabel; } 如果_timeLabel = self,由于self.timerLabel是strong,会形成retainCircle 2 timer 和self 也会形成retain circle,需要在不使用timer时调用一下cleanTimerLabel,比如在一个ViewController的dealloc中调用cle anTimerLabel --- MZTimerLabel/MZTimerLabel.h | 3 ++- MZTimerLabel/MZTimerLabel.m | 9 ++++++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/MZTimerLabel/MZTimerLabel.h b/MZTimerLabel/MZTimerLabel.h index 5895aec..0a3c8f8 100644 --- a/MZTimerLabel/MZTimerLabel.h +++ b/MZTimerLabel/MZTimerLabel.h @@ -72,7 +72,7 @@ typedef enum{ @property (nonatomic,copy) NSString *timeFormat; /*Target label obejct, default self if you do not initWithLabel nor set*/ -@property (nonatomic,strong) UILabel *timeLabel; +@property (nonatomic,weak) UILabel *timeLabel; /*Used for replace text in range */ @property (nonatomic, assign) NSRange textRange; @@ -110,6 +110,7 @@ typedef enum{ #endif -(void)pause; -(void)reset; +- (void)cleanTimerLabel; /*--------Setter methods*/ -(void)setCountDownTime:(NSTimeInterval)time; diff --git a/MZTimerLabel/MZTimerLabel.m b/MZTimerLabel/MZTimerLabel.m index ee33133..670d8b7 100644 --- a/MZTimerLabel/MZTimerLabel.m +++ b/MZTimerLabel/MZTimerLabel.m @@ -101,7 +101,14 @@ - (id)initWithCoder:(NSCoder *)aDecoder #pragma mark - Cleanup -- (void) removeFromSuperview { +- (void)cleanTimerLabel { + if (_timer) { + [_timer invalidate]; + _timer = nil; + } +} + +- (void)removeFromSuperview { if (_timer) { [_timer invalidate]; _timer = nil; From a3fc15345c85071ea22b9d115501de99b0136ec3 Mon Sep 17 00:00:00 2001 From: Coderzhangsl Date: Thu, 2 Jun 2016 15:31:48 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E5=80=92=E8=AE=A1=E6=97=B6=E4=BC=9A?= =?UTF-8?q?=E5=B0=91=E4=B8=80=E7=A7=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 倒计时会少一秒 --- MZTimerLabel/MZTimerLabel.m | 1 + 1 file changed, 1 insertion(+) diff --git a/MZTimerLabel/MZTimerLabel.m b/MZTimerLabel/MZTimerLabel.m index 670d8b7..ea01b11 100644 --- a/MZTimerLabel/MZTimerLabel.m +++ b/MZTimerLabel/MZTimerLabel.m @@ -133,6 +133,7 @@ - (void)setCountDownTime:(NSTimeInterval)time{ timeUserValue = (time < 0)? 0 : time; timeToCountOff = [date1970 dateByAddingTimeInterval:timeUserValue]; + timeToCountOff = [timeToCountOff dateByAddingTimeInterval:0.99]; [self updateLabel]; }