0
함수에서 프로그래밍 방식으로 레이블을 만들고이를 NSMutableArray에 넣은 다음 다른 함수에서 레이블을 삭제합니다. 문제는 레이블이 실제로 화면에서 사라지지만 메모리를 사용하고 있으며 시간이 지나면 프로그램이 매우 느리게 작동하기 시작한다는 것입니다.RemoveFromSuperview가 정리 메모리가 아닙니다.
이 레이블을 생성하는 기능은 다음과 같습니다
여기 내 코드입니다.
- (void)CrearEstrellas{
for(int i=0; i< 10; i++)
{
float x = arc4random() %300;
float y = arc4random() %100;
UILabel *estrella = [[UILabel alloc] initWithFrame:CGRectMake(0, 100, 4, 4)];
estrella.tag = i;
estrella.center = CGPointMake(x,y-100);
estrella.text = @".";
estrella.textColor = [UIColor whiteColor];
[self.view.superview addSubview: estrella];
[arrayEstrellas insertObject:(estrella) atIndex: i];
}
}
그리고 이것은 수퍼에서 삭제하는 기능은 다음과 같습니다
- (void)Lineatiempo{
for(int i=0; i<[arrayEstrellas count]; i++)
{
UILabel *estrella = [arrayEstrellas objectAtIndex:(i)];
float x = estrella.center.x;
float y = estrella.center.y;
estrella.center = CGPointMake(x,y+10);
if(estrella.center.y>200){
[estrella removeFromSuperview];
estrella = nil;
}
}
}
내가 뭘 잘못 알고 싶다! 감사.
그게 다야 [arrayEstrellas removeObjectAtIndex : i]; 지금은 잘 작동하고 있습니다. 고마워요! – Legendar
루프를 수정하는 것을 잊지 마십시오. 항목을 반복하는 동안 항목을 제거하면 일부보기가 무시됩니다. – DrummerB