如何让之前的标签消失并被释放?
如何让之前的“标签框”消失并被释放? 我释放了该对象,但当我点击并移动时,它仍然只是在“标签框”顶部创建新的“标签框”。
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
CGPoint nowPoint = [[touches anyObject] locationInView:self.view];
CGPoint prevPoint = [[touches anyObject] previousLocationInView:self.view];
CGRect RectFrame1;
RectFrame1 = CGRectMake(nowPoint.x, nowPoint.y, 280, 30);
UILabel *label = [[UILabel alloc] initWithFrame:RectFrame1];
label.text = [NSString stringWithFormat:@"x %f y %f", nowPoint.x, nowPoint.y];
label.backgroundColor = [UIColor blackColor];
label.textColor = [UIColor whiteColor];
[self.view addSubview:label];
[label release];
//[self release];
//[&RectFrame1 release];
}
How to make the previous "label box" disappear and be released?
I release the object but it still just creates new "label boxes" on top of "label boxes" when I tap and move.
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[super touchesMoved:touches withEvent:event];
CGPoint nowPoint = [[touches anyObject] locationInView:self.view];
CGPoint prevPoint = [[touches anyObject] previousLocationInView:self.view];
CGRect RectFrame1;
RectFrame1 = CGRectMake(nowPoint.x, nowPoint.y, 280, 30);
UILabel *label = [[UILabel alloc] initWithFrame:RectFrame1];
label.text = [NSString stringWithFormat:@"x %f y %f", nowPoint.x, nowPoint.y];
label.backgroundColor = [UIColor blackColor];
label.textColor = [UIColor whiteColor];
[self.view addSubview:label];
[label release];
//[self release];
//[&RectFrame1 release];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您想从视图中删除它,请使用
removeFromSuperview
If you want to remove it from the view use
removeFromSuperview
你到底想做什么。您想删除标签吗?
[label release]
将从内存中而不是从视图中释放实例。[label removeFromSuperview]
将从视图中删除。但将其添加到超级视图然后立即将其删除似乎很奇怪。What you exactly mean to do. Do you want to remove the label.
[label release]
will release the instance from memory not from the view.[label removeFromSuperview]
will remove from view. But adding it to superview and then removing it immediately seems odd.我认为您正在标签上显示每个触摸点。您可以通过修改代码来解决问题...
希望这对您有帮助....:)
I think you are displaying each touched point on a label. You can solve the issue by modifying your code...
Hope this helps you .... :)