我有一個登錄界面,我在一個地方分配,而在另一個解僱,並在解僱,其dealloc
方法不會被調用和伊娃拿着登錄屏幕,即使在我被解僱的代碼被分配零後仍然具有價值。如何取消分配我的視圖控制器?
這裏是我的配置
-(void)loginUser
{
loginScreen = [[LoginScreen alloc] initWithNibName:@"LoginScreen" bundle:nil];
[self.tabBarController addChildViewController:loginScreen];
[self.tabBarController.view addSubview:loginScreen.view];
[loginScreen didMoveToParentViewController:self.tabBarController];
[self.tabBarController.view bringSubviewToFront:loginScreen.view];
}
這是我的解僱和重新分配的另一種方法(不取消分配)
[UIView animateWithDuration:0.4 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
loginScreen.view.frame = CGRectOffset(frame, -1024, 0);
}
completion:^(BOOL finished) {
// Remove the loginScreen
[loginScreen willMoveToParentViewController:nil];
[loginScreen.view removeFromSuperview];
[loginScreen removeFromParentViewController];
[loginScreen cleanupBeforeDealloc];
loginScreen = nil;
}];
我有一些代碼,監聽鍵盤的通知在LoginScreen裏面,但是我在下面添加了一個方法來清理它,並且我試着在上面的解僱代碼中調用它,但是仍然沒有解決它。 GRRRR。
-(void)cleanupBeforeDealloc
{
[self deregisterFromKeyboardNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
你有什麼讓你的loginScreen內的強引用本身。如果你想讓我們知道它是什麼,請添加你的loginScreen代碼。你不會手動釋放你的viewControllers,ARC會爲你處理。 – 2017-02-28 21:06:49
@Sneak。不,我很抱歉,我沒有任何東西保留有力的參考。我用正則表達式'loginscreen'搜索了我的整個項目,代碼中的每個實例/用法都在上面兩種方法中進行了說明。我打算髮布截圖,但是stackoverflow/imagur目前無法接受圖片上傳。 –
沒錯。如果'dealloc'沒有被調用時,你有一個保留週期。您可以使用「泄漏」工具來追蹤它。 – matt