2
我很困惑!设置UILabel.text属性会导致线程中的内存泄漏
我有一个计时器设置,在定时器内运行倒计时器,我更新了UILabels的时间,这一切都很好,但奇怪的是,当我测试仪器时,文本的设置会导致内存泄漏。
计时码
NSTimer* timer = [NSTimer timerWithTimeInterval:1.0f
target:self
selector:@selector(myTimer:)
userInfo:nil
repeats:YES];
self.pnTimer = timer;
[[NSRunLoop mainRunLoop] addTimer:self.pnTimer forMode:NSRunLoopCommonModes];
我的计时方法有以下...
- (void)myTimer:(NSTimer*)timer {
...
if (self.secondsPassed <=9) {
[self.secondsLabel setText:[NSString stringWithFormat:@"0%i",self.secondsPassed]];
} else {
[self.secondsLabel setText:[NSString stringWithFormat:@"%i",self.secondsPassed]];
}
...
}
注释掉[self.secondsLabel ...线,并在#Living在寻找仪器列,它大致保持在原来的位置,但允许代码运行并更新标签,导致#Living列不断增加,直到应用程序变得缓慢且无响应(20分钟左右)
标签定义为
@property (weak, nonatomic) IBOutlet UILabel *secondsLabel;
请注意,我还使用的是iOS 6.1
任何想法的iPhone 5的设备我可能是错在这里做的检验呢? 感谢您的帮助
唉,这可怕的格式化破解!请改用'[NSString stringWithFormat:@“%02d”,self.secondsPassed]'。 – 2013-02-18 12:05:12
-myTimer:还有什么呢? – Moxy 2013-02-18 12:18:35
那么,除了self.secondsPassed--;当我将其缩小到更新标签时,我已经评论了其他所有内容。 – GeoffCoope 2013-02-18 12:24:55