我有2个控制器InitViewController和SettingsViewController.每个视图都有一个调用另一个视图的按钮:
InitViewController
@interface InitViewController : UIViewController
- (IBAction)loadSettings:(id)sender;
@end
@implementation InitViewController
- (IBAction)loadSettings:(id)sender {
SettingsViewController *vc = [[SettingsViewController alloc] initWithNibName:@"SettingsViewController" bundle:nil];
[self presentViewController:vc animated:YES completion:nil];
vc = nil;
}
@end
Run Code Online (Sandbox Code Playgroud)
SettingsViewController
@interface SettingsViewController : UIViewController
- (IBAction)back:(id)sender;
@end
@implementation SettingsViewController
- (IBAction)back:(id)sender {
InitViewController *vc = [[InitViewController alloc] initWithNibName:@"InitViewController" bundle:nil];
[self presentViewController:vc animated:YES completion:nil];
vc = nil;
}
@end
Run Code Online (Sandbox Code Playgroud)
虽然我通过多次点击按钮来分析应用程序并测试它,但我看到InitViewController和SettingsViewController的实例仍然存在=> 
我究竟做错了什么?
你SettingsViewController不会回到InitViewController创造它的那个.相反,它会创建一个新实例InitViewController并呈现它.所以你最终得到一堆视图控制器,在InitViewController和的实例之间交替SettingsViewController.
因为在呈现它之后你永远不会忽略任何类型的视图控制器,所以它们都不能被释放.
你的-[SettingsViewController back:]行动应该解雇自己,而不是创造和呈现新的InitViewController.
@implementation SettingsViewController
- (IBAction)back:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2174 次 |
| 最近记录: |