ios - UILabel 更新文本,但不会删除旧文本
<p><p>编辑:我发现我需要删除 subview ,一旦 View 确实消失了</p>
<pre><code>[makeObjectsPerformSelector:@selector(removeFromSuperview)];
</code></pre>
<p>我的问题是我有一个 <code>UILabel</code> 可以正确更新文本,但不会删除旧文本。我想可能是因为有 2 个 <code>UILabels</code> 在彼此之上,这是它的图片:</p>
<p> <img src="/image/vwHMg.png" alt="enter image description here"/> </p>
<p>这是我的代码。我看不到副本在哪里:</p>
<pre><code> for (int i = 0; i < array1.count; i++) {
NSNumber *myNumber = ;
float myScore = myNumber.floatValue;
NSNumber *levelNumber = ;
float levelScore = levelNumber.floatValue;
for (int i = 0; i < array1.count; i++) {
NSNumber *myNumber = ;
float myScore = myNumber.floatValue;
NSNumber *levelNumber = ;
float levelScore = levelNumber.floatValue;
float progressScore = ((float)myScore/(float)levelScore);
CGRect frame;
frame.origin.x = self.scrollView.frame.size.width * i;
frame.origin.y = 0;
frame.size = self.scrollView.frame.size;
UIView *subview = [ initWithFrame:frame];
subview.backgroundColor = ;
NSArray *colorArray = ;
// Labeled progress views
self.labeledProgressView = [
initWithFrame:CGRectMake(25.0f, 20.0f, 100.0f, 100.0f)];
self.labeledProgressView.roundedCorners = NO;
self.labeledProgressView.trackTintColor = ;
imageLevel = [ initWithFrame:CGRectMake(25.0f, 20.0f, 100.0f, 100.0f)];
imageLevel.backgroundColor = ;
self.Scoreint = [ initWithFrame:CGRectMake(-25.0f, 130, 195, 21)];
self.Scoreint.backgroundColor = ;
self.Scoreint.textColor = ;
];
self.Scoreint.textAlignment = NSTextAlignmentCenter;
self.Scoreint.text = @"";
if (myScore == 0) {
NSString *scoreString = ;
;
}
else {
NSString *scoreString = ;
;
}
;
</code></pre>
<p>我希望你们中的一些人可以帮助我解决这个问题! :)</p></p>
<br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
<p><p>另一种方式,你应该这样做,它每次都从 superView 中删除标签,然后再初始化它。</p>
<p>你这样修改代码,</p>
<pre><code>if(self.Scoreint) {
;
}
self.Scoreint = [ initWithFrame:CGRectMake(-25.0f, 130, 195, 21)];
self.Scoreint.backgroundColor = ;
self.Scoreint.textColor = ;
];
self.Scoreint.textAlignment = NSTextAlignmentCenter;
self.Scoreint.text = @"";
</code></pre></p>
<p style="font-size: 20px;">关于ios - UILabel 更新文本,但不会删除旧文本,我们在Stack Overflow上找到一个类似的问题:
<a href="https://stackoverflow.com/questions/24486180/" rel="noreferrer noopener nofollow" style="color: red;">
https://stackoverflow.com/questions/24486180/
</a>
</p>
页:
[1]