IOS:当我输入时删除子视图
我有这段代码来显示子视图并删除它:
if(view1 == nil){
view1 = [[Calendar alloc] initWithNibName:@"Calendar" bundle:nil];
[view1 setDelegate:self];
[self.view addSubview:view1.view];
view1.view.frame = CGRectMake(250, 0, 550, 400);
}
删除它:
[view1.view removeFromSuperview];
view1 = nil;
[view1 release];
当我在这个子视图“view1”内按下按钮时它工作正常,但是如果我从这个视图中键入,也可以删除这个视图吗?
I have this code to show a subview and to remove it:
if(view1 == nil){
view1 = [[Calendar alloc] initWithNibName:@"Calendar" bundle:nil];
[view1 setDelegate:self];
[self.view addSubview:view1.view];
view1.view.frame = CGRectMake(250, 0, 550, 400);
}
remove it:
[view1.view removeFromSuperview];
view1 = nil;
[view1 release];
it work fine when I push a button inside this subview "view1" but is possible remove this view also if I type out of this view?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在发布之前先将其设为 nil 是没有意义的;您已经销毁了引用,因此该变量不再连接到任何东西。调用release 是行不通的。
making it nil first before a release is pointless; you've already destroyed the reference, so the variable is no longer connected to anything. calling release on it won't work.