从后退/完成按钮中删除 UIView
我有一个小应用程序,主屏幕上有几个按钮,当单击这些按钮时会在新视图中加载,这一切都工作正常:
- (IBAction)showMaps:(id)sender {
MapViewController *viewcontroller = [[MapViewController alloc] initWithNibName:@"MapView" bundle:nil];
[[self view] addSubview:viewcontroller.view];
[viewcontroller release];
}
加载 MapView 时出现问题我在 MapViewController.h 文件中创建了一个新的 IBAction :
- (IBAction)showHome:(id)sender;
还有 MapViewController.m 文件中的这个操作:
- (IBAction)showHome:(id)sender {
[self.view removeFromSuperview];
}
但是没有乐趣,对此有点新手,所以非常欢迎任何帮助!
I have a small app that from the home screen has a few buttons, when clicked these buttons load in a new view, this all works fine:
- (IBAction)showMaps:(id)sender {
MapViewController *viewcontroller = [[MapViewController alloc] initWithNibName:@"MapView" bundle:nil];
[[self view] addSubview:viewcontroller.view];
[viewcontroller release];
}
The problem comes when the MapView is loaded I have created a new IBAction in the MapViewController.h file:
- (IBAction)showHome:(id)sender;
And also this action within the MapViewController.m file:
- (IBAction)showHome:(id)sender {
[self.view removeFromSuperview];
}
But no joy, bit of a newbie to this so any help more than welcome!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的
showMaps:
方法创建一个视图控制器,但不保留它。如果您希望该 viewController 保留下来,您将需要保留该 viewController 的所有权。我建议在主视图控制器上添加一个属性 - 包含showMaps:
方法的属性。示例代码如下:Your
showMaps:
method creates a view controller, but does not retain it. You will need to retain ownership of that viewController if you want it to stick around. I would suggest adding a property on your main view controller - the one that contains theshowMaps:
method. Example code below: