【发布时间】:2014-04-28 02:16:27
【问题描述】:
我一直试图从其他 ViewController 调用的操作中删除我的视图,但我不知道该怎么做
这是我的代码:
+ (Menu *)Mostrar:(UIView *)view{
CGRect IMGFrame = CGRectMake( 5, 20, 70, 70 );
UIButton *boton=[[UIButton alloc] initWithFrame:IMGFrame];
[boton setBackgroundImage:[UIImage imageNamed:@"Logo_SuperiorBTN.png"] forState:UIControlStateNormal];
[boton setBackgroundImage:[UIImage imageNamed:@"Logo_SuperiorBTN.png"] forState:UIControlStateSelected];
[boton addTarget: self action: @selector(cerrarmenu:) forControlEvents: UIControlEventTouchUpInside];
[boton setTag:899];
[view addSubview: boton];
}
这部分是像这样从我的MainViewController 调用的
-(IBAction)menu:(id)sender{
Menu *hudView = [Menu Mostrar:self.view];
}
然后它显示视图,当我尝试使用按钮关闭它时它崩溃
关闭菜单的代码是
+(void)cerrarmenu:(UIView *)view{
for (UIView *subView in view) {
if (subView.tag == 899) {
[subView removeFromSuperview];
}
}
}
谢谢 圣地亚哥
【问题讨论】:
-
"view.subviews" 是要循环的视图数组。但请不要这样做。
-
你的视图是自定义视图??并且您已将其添加到 MainViewController?现在您想在单击按钮时将其从 MainViewController 中删除(此按钮属于您的自定义视图)。对吗?
标签: ios objective-c uiview selector subview