【发布时间】:2014-07-03 15:25:56
【问题描述】:
我的 NavigationController 有两个控制器。当我去第二个控制器时,一切都很好。但是,当我返回第一个控制器然后再次返回第二个时,使用的内存量会增加(每次第二个控制器再次加载时,内存都会永久增长)。在处理重复加载的viewDidLoad 方法中,_loadServicesView、_complexTableView 和_selectTypeCarView 等对象被设置为 nil,然后再次创建。为什么这些对象在从第二个控制器转换到第一个控制器时没有被销毁?另外,如果它们没有被销毁,为什么它们被设置为零?
下面是第二个控制器的相关代码:
@interface WCselectTypeViewController () <UITableViewDataSource, UITableViewDelegate>
@property (strong, nonatomic) WCloadServices *loadServices;
@property (strong, nonatomic) WCloadView *loadServicesView;
@property (strong, nonatomic) WCselectTypeView *selectTypeView;
@property (strong, nonatomic) WCcomplexTableView *complexTableView;
@end
@implementation WCselectTypeViewController
- (void)loadView
{
[super loadView];
}
- (void)viewDidLoad
{
[super viewDidLoad];
if (!_loadServicesView)
{
_loadServicesView = [[WCloadView alloc] init];
[_loadServicesView setDelegate:self];
[self.view addSubview:_loadServicesView];
}
if (!_complexTableView)
{
_complexTableView = [[WCcomplexTableView alloc] initWithViewConfig:[WCappConfig getViewConfig]];
_complexTableView.alpha = 0;
_complexTableView.delegate = self;
_complexTableView.dataSource = self;
[self.view addSubview:_complexTableView];
}
if (!_selectTypeView)
{
_selectTypeView = [[WCselectTypeCarView alloc] initWithViewConfig:[WCappConfig getViewConfig] andType:[[WCorderStored sharedStore] getType]];
[_selectTypeCarView setDelegate:self];
[self.view addSubview:_selectTypeView];
}
}
【问题讨论】:
-
如何从一个控制器到另一个控制器再返回?是否使用故事板转场?您是否创建了一个转场以“返回”(错误)
-
我不使用故事板或 xib。仅以编程方式创建的 UIView
-
确保您的“代表”是“弱”而不是“强”。 “WCselectTypeViewController”将“WCloadView”的实例保持为“strong”,并且“WCloadView”“delegate”设置为“WCselectTypeViewController”。可能的保留周期。
-
那么,你能回答我的问题吗?如何从一个控制器转到下一个控制器,然后返回?
-
我去下一个控制器——WCselectTypeViewController *selectTypeViewController = [[WCselectTypeViewController alloc] init]; [self.navigationController pushViewController:selectTypeCarViewController 动画:YES];
标签: ios objective-c xcode memory