编辑:我发现我需要删除 subview ,一旦 View 确实消失了
[[self.scrollView subviews]makeObjectsPerformSelectorselector(removeFromSuperview)];
我的问题是我有一个 UILabel 可以正确更新文本,但不会删除旧文本。我想可能是因为有 2 个 UILabels 在彼此之上,这是它的图片:
这是我的代码。我看不到副本在哪里:
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];
我希望你们中的一些人可以帮助我解决这个问题!
Best Answer-推荐答案 strong>
另一种方式,你应该这样做,它每次都从 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/
|