如何更新子视图?
我想更新一个像这样创建的子视图:
CGRect keyLabelRect = CGRectMake(2, [heightofrow intValue]*i, [breitescroller2 intValue]-2,[heightofrow intValue]);
UILabel *keyLabel = [[UILabel alloc] initWithFrame:keyLabelRect];
[Inhalt1 addSubview: keyLabel];
[keyLabel release];
通过调用一个方法,“breitescroller2”获得了一个新值,这个术语被称为第二次和第三次,依此类推。我的问题是,具有旧位置的“旧 UILabel”保留在视图中,但我想用新位置替换它。有没有简单的方法呢?通过删除整个子视图(keyLabelremoveFromSuperView],较新的子视图也被删除。
感谢您的帮助!
I want to renew a subview which is created like this:
CGRect keyLabelRect = CGRectMake(2, [heightofrow intValue]*i, [breitescroller2 intValue]-2,[heightofrow intValue]);
UILabel *keyLabel = [[UILabel alloc] initWithFrame:keyLabelRect];
[Inhalt1 addSubview: keyLabel];
[keyLabel release];
By calling a method, "breitescroller2" got a new value and this term is called a second time and a third time and so on. My problem is, that the "older UILabel" with the old position stay at the view, but i want to replace it with the new position. Is there a simple method? by deleting the whole subview (keyLabel removeFromSuperView] the newer one's are deleted too.
Thanks for help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您这样做,那么简单地修改现有 UILabel 的属性而不是每次都创建一个新的属性不是更有意义吗?在我看来,按照你现在的方式做,特别是当你想用新的替换旧的时,在记忆方面有点低效。
不过,我只是使用 Cocoa 和 Obj-C 的初学者,所以我可能会错过一些使我的建议不可行的东西。
If you're doing it like that, would it not make more sense to simply modify the properties of the existing UILabel and not keep creating a new one each time? It seems to me that doing it the way you are now, especially since you want to replace the old one with the new one, is a bit inefficient memory-wise.
I'm only a beginner at working with Cocoa and Obj-C, though, so I might be missing something that makes my suggestion unfeasible.
我很确定您首先需要通过removeFromSuperview 删除旧标签。
I'm pretty sure you first need to remove the old label via removeFromSuperview.