Iphone 旧视图与新视图重叠
我有以下问题: 在我的应用程序中,我正在以以下方式创建一个临时对象,例如标签:Iphone 旧视图与新视图重叠,iphone,cocoa-touch,Iphone,Cocoa Touch,我有以下问题: 在我的应用程序中,我正在以以下方式创建一个临时对象,例如标签: UILabel *tempLabel = [ [UILabel alloc] initWithFrame: CGRectMake(100, 5, 200, 30)]; tempLabel.backgroundColor = [UIColor colorWithRed: 1.0f green: 1.0f blue: 1.0f alpha: 0.0f]; tempLabel.text = [ [WordsDatabase
UILabel *tempLabel = [ [UILabel alloc] initWithFrame: CGRectMake(100, 5, 200, 30)];
tempLabel.backgroundColor = [UIColor colorWithRed: 1.0f green: 1.0f blue: 1.0f alpha: 0.0f];
tempLabel.text = [ [WordsDatabase sharedWordsDatabase] dbName];
[ [self view] addSubview: tempLabel];
[tempLabel release];
正在从ViewWillAppeard方法调用此代码
当视图本身第一次被调用时,一切都很好。但第二次,新标签似乎与旧标签重叠
是否需要采取任何措施来消除这种影响?
要添加到ViewWillEnglishe方法中的内容
我尝试将标签声明添加到类接口中,并在ViewWillEnglishe方法中调用[label removeFromSuperview]。在这种情况下,一切都很好。
有没有一种方法可以在不存储标签引用的情况下完成此操作
先谢谢你 您可以使用
sortSubviewsUsingFunction:context:
方法对子视图进行排序。
实现这一点的一种方法是向每个子视图添加一个带有整数值的标记(UIView的tag
属性)。然后,您可以像这样按标记排序(假设标记是一个数字):
排序功能:
int viewObjectSortByTag(NSControl *firstView, NSControl *secondView, void *context) {
return ([firstView tag] > [secondView tag]) ? NSOrderedAscending : NSOrderedDescending;
}
添加子视图后,只需对视图进行排序:
[[self view] sortSubviewsUsingFunction:&viewObjectSortByTag context:nil];