gpt4 book ai didi

ios - UILabel 更新文本,但不会删除旧文本

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:22:26 24 4
gpt4 key购买 nike

编辑:我发现我需要删除 subview ,一旦 View 消失

[[self.scrollView subviews]makeObjectsPerformSelector:@selector(removeFromSuperview)];

我的问题是我有一个 UILabel 可以正确更新文本,但不会删除旧文本。我想可能是因为有 2 个 UILabels 相互叠加,这是它的图片:

enter image description here

这是我的代码。我看不到副本在哪里:

    for (int i = 0; i < array1.count; i++) {

NSNumber *myNumber = [myscoretext objectAtIndex:i];
float myScore = myNumber.floatValue;

NSNumber *levelNumber = [neededscoretext objectAtIndex:i];
float levelScore = levelNumber.floatValue;

for (int i = 0; i < array1.count; i++) {

NSNumber *myNumber = [myscoretext objectAtIndex:i];
float myScore = myNumber.floatValue;

NSNumber *levelNumber = [neededscoretext objectAtIndex:i];
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 = [[UIView alloc] initWithFrame:frame];
subview.backgroundColor = [UIColor clearColor];

NSArray *colorArray = [NSArray arrayWithObjects:edmeral, turqouise, orange, red, nil];
// Labeled progress views
self.labeledProgressView = [[DALabeledCircularProgressView alloc]
initWithFrame:CGRectMake(25.0f, 20.0f, 100.0f, 100.0f)];
self.labeledProgressView.roundedCorners = NO;
self.labeledProgressView.trackTintColor = [UIColor colorWithWhite:1.0f alpha:0.8];

imageLevel = [[UIImageView alloc] initWithFrame:CGRectMake(25.0f, 20.0f, 100.0f, 100.0f)];
imageLevel.backgroundColor = [UIColor clearColor];


self.Scoreint = [[UILabel alloc] initWithFrame:CGRectMake(-25.0f, 130, 195, 21)];
self.Scoreint.backgroundColor = [UIColor clearColor];
self.Scoreint.textColor = [UIColor blackColor];
[self.Scoreint setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:15]];
self.Scoreint.textAlignment = NSTextAlignmentCenter;
self.Scoreint.text = @"";


if (myScore == 0) {

NSString *scoreString = [NSString stringWithFormat:@"0 / %5ld", (long)levelScore];
[self.Scoreint setText:scoreString];
}
else {

NSString *scoreString = [NSString stringWithFormat:@"%5li / %5li", (long)myScore, (long)levelScore];
[self.Scoreint setText:scoreString];

}

[subview addSubview:Scoreint];

我希望你们中的一些人能帮助我解决这个问题! :)

最佳答案

换句话说,你应该这样做,它每次都从 superView 中删除标签,然后再初始化它。

你这样修改代码,

if(self.Scoreint) {
[self.Scoreint removeFromSuperview];
}
self.Scoreint = [[UILabel alloc] initWithFrame:CGRectMake(-25.0f, 130, 195, 21)];
self.Scoreint.backgroundColor = [UIColor clearColor];
self.Scoreint.textColor = [UIColor blackColor];
[self.Scoreint setFont:[UIFont fontWithName:@"HelveticaNeue-Thin" size:15]];
self.Scoreint.textAlignment = NSTextAlignmentCenter;
self.Scoreint.text = @"";

关于ios - UILabel 更新文本,但不会删除旧文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24486180/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com