[英]iOS 7: Custom UILabel new value prints on old value
我的自定义UILabel
每次在[self refreshInterface]
方法中创建,每次在[viewWillAppear]
方法中调用。 在我导航到其他UIViewController
并返回UILabel
新文本之前,它工作正常。
新数据打印在前一个数据上,看起来很丑。 如何在打印出新label.text
之前摆脱我的label.text
的旧值。
码:
if(_coin.dublicates.count>0)
{
UILabel *lbl=[[UILabel alloc]initWithFrame:CGRectMake(25.0, 13.0, 60.0, 20.0)];
lbl.font=[UIFont fontWithName:@"Lato-Regular" size:8];
lbl.textAlignment=NSTextAlignmentCenter;
lbl.textColor=[UIColor colorWithPatternImage:[UIImage imageNamed:@"greenBg"]];
lbl.text=[NSString stringWithFormat:@" +%lu",(unsigned long)_coin.dublicates.count];
[_toolbar addSubview:lbl];
}
您的视图控制器正在保存其视图。 当您返回viewController
并创建一个新的UILabel
,它会出现在上一个UILabel
上。
就像rmaddy在评论中所说:
将UILabel
绑定到您的类的属性( viewcontroller
),然后重新分配文本。 那绝对是最简单的解决方案。 self.yourLabel.text = @"The text you want to assign";
该视频大约在2:00分钟标记,说明了如何从XIB
或storyboard
IBoutlet
中的标签创建IBoutlet
。 http://teamtreehouse.com/library/build-a-simple-iphone-app/getting-started-with-iphone/what-is-an-iboutlet-2
你可以然而,在- (void)viewWillDisappear {}
删除UILabel
通过获取子视图的列表和检查UILabel
,然后脱除。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.