Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Iphone 旧视图与新视图重叠_Iphone_Cocoa Touch - Fatal编程技术网

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];