Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/objective-c/27.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/assembly/5.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 调用removeFromSuperview“后;“接口构建”;物品不见了?_Iphone_Objective C_Xcode - Fatal编程技术网

Iphone 调用removeFromSuperview“后;“接口构建”;物品不见了?

Iphone 调用removeFromSuperview“后;“接口构建”;物品不见了?,iphone,objective-c,xcode,Iphone,Objective C,Xcode,我在interface builder中有一个正常的交互(有一个UILabel和一个UIButton)。在代码中,我创建了一个uicrollview,其中包含(未知)数量的UILabels(取决于用户)。这些标签是在-(void)视图中创建的,将显示,以确保数据是最新的。要删除标签,在视图中将消失我正在呼叫 for(UIView *subview in [scrollView subviews]) { [subview removeFromSuperview]; } 问题是,再次调用

我在interface builder中有一个正常的交互(有一个
UILabel
和一个
UIButton
)。在代码中,我创建了一个
uicrollview
,其中包含(未知)数量的
UILabels
(取决于用户)。这些标签是在
-(void)视图中创建的,将显示
,以确保数据是最新的。要删除标签,在
视图中将消失
我正在呼叫

for(UIView *subview in [scrollView  subviews])
{
    [subview removeFromSuperview];
}

问题是,再次调用视图get后,使用interfacebuilder创建的对象(
UILabel
&
UIButton
)消失。是否通过调用
[subview removeFromSuperview]来删除该视图?如果是,如何再次添加?由代码创建的所有内容仍然存在…

不要删除所有子视图。仅删除您在
视图中添加的标签将显示

您应该向动态添加的标签添加标签

for(int i = 0; i < n; i++){
  UILabel *label = [UILabel alloc...];
  label.tag = 999999;
}

UILabel、UIButton和UIExtFields基本上是UIView的子类。 因此,如果删除scrollview下的所有UIView,它也会删除它们

for (UIView *myView in [scrollView  subviews]) {
    if([myView isKindOfClass:[UILabel class]]){
        [myView removeFromSuperview];
    }
    if([myView isKindOfClass:[UIButton class]]){
        [myView removeFromSuperview];
    }
    if([myView isKindOfClass:[UITextField class]]){
        [myView removeFromSuperview];
    }
}

我不能。标签是在for中创建的(int i=0;ifor (UIView *myView in [scrollView subviews]) { if([myView isKindOfClass:[UILabel class]]){ [myView removeFromSuperview]; } if([myView isKindOfClass:[UIButton class]]){ [myView removeFromSuperview]; } if([myView isKindOfClass:[UITextField class]]){ [myView removeFromSuperview]; } }