我正在尝试将 UILabel 添加/删除到 ScrollView。添加进行得很好,但在添加新标签之前,我似乎无法删除标签。任何人都可以对这种情况有所了解吗?
-(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.
}