Ich versuche, UILabels zu einem ScrollView hinzufügen/entfernen. Das Hinzufügen funktioniert gut, aber ich kann die Labels nicht entfernen, bevor ich neue hinzufüge. Kann jemand diese Situation beleuchten?UIScrollView - Hinzufügen/Entfernen von Labels
-(void)setMessage:(MessageData *)m{
//Attempting to remove any previous labels
iPhone_PNPAppDelegate *mainDelegate = (iPhone_PNPAppDelegate *)[[UIApplication sharedApplication] delegate];
UILabel *l;
for (NSInteger i=0; i<[[scrollView subviews] count]; i++){
l=[[scrollView subviews] objectAtIndex:0];
[l removeFromSuperview];
l=nil;
}
//Adding my new Labels
CGPoint pt=CGPointMake(5,5);
if ([[[mainDelegate messageFieldCaptions] objectAtIndex:0] length]>0){
NSArray *p=[[[mainDelegate messageFieldCaptions] objectAtIndex:0] componentsSeparatedByString:@"|"];
l= [self newLabelWithPrimaryColor:[mainDelegate navColor] selectedColor:[UIColor whiteColor] fontSize:12.0 bold:YES];
if (m.sValue0.length>0)
l.text=[NSString stringWithFormat:@"%@ %@",[p objectAtIndex:0], m.sValue0];
else
l.text=[NSString stringWithFormat:@"%@ None",[p objectAtIndex:0]];
[l setFrame:CGRectMake(pt.x,pt.y,310,20)];
[scrollView addSubview:l];
[l release];
pt.y+=20;
}
//This is done about 10 more times to add new labels.
}
Das sehr seltsame daran ist, dass etwa die Hälfte der Etiketten entfernt werden, während die anderen nicht ... so komisch .... – Dutchie432