Remove label from scrollview
I am creating an iPhone app in which i am using scrollview and adding labels like this :
question = [[UILabel alloc] initWithFrame:CGRectMake(22, 130, 725, 160)] ;
question.textColor = [UIColor blueColor];
question.text = [NSString stringWithFormat:@"%@" ,selected];
question.lineBreakMode = UILineBreakModeWordWrap;
[question setFont:[UIFont fontWithName:@"Futura" size:30]];
question.backgroundColor = [UIColo开发者_开发知识库r clearColor];
question.numberOfLines = 0;
[question sizeToFit];
[self.view addSubview:question];
[scrollview addSubview:question];
now i want to remove this label from scrollview. So how can i do this..??
i am doing this for remove object from main view. [question removeFromSuperview];
Thanks.
There are some problems in your code. I assume that the scrollview is a subview of self.view
. In this case remove the line
[self.view addSubview: question];
from you code. Depending on the rest of your code I would eventually also change the first line. If you don't need to excess the label somewhere else in your code I would change the first line to
UILabel *question = [[UILabel alloc] initWithFrame: CGRectMake(22, 130, 725, 160)];
and add a line after [scrollview addSubview: question];
with
[question release];
This would reduce you memory consumption.
Why are you adding question
to the main view and to the scroll view? It doesn't make sense. Remove the [self.view addSubview:question];
line and [question removeFromSuperview];
will remove your label from the scrollview.
精彩评论