簡體   English   中英

Viewcontroller Dealloc方法永遠不會被調用

[英]Viewcontroller Dealloc Method Never Gets Called

我知道有很多這樣的問題。 我看完了 我的問題很簡單。

我從xcode文件>新建項目>單視圖應用程序創建了一個單視圖應用程序。 然后,我在情節提要中添加了第二個uiviewcontroller和一個名為secondViewController的新viewcontroller類。 我將一個按鈕拖到主viewcontroller上,然后按ctrl + drag拖到情節提要上的secondViewController上。 我在secondViewController中做了相反的操作。 只需將帶有nslog的dealloc functins添加到類文件中。 我還為uibuttons添加了弱引用

視圖更改時,永遠不會調用每個viewcontroller的Dealloc方法。

ViewController.m

#import "ViewController.h"

@interface ViewController ()

@end

@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    NSLog(@"viewDidLoad 1");
        // Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    NSLog(@"dealloc 1");
}

SeconViewController.m

#import "SecondViewController.h"

@interface SecondViewController ()

@end

@implementation SecondViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)dealloc {
    NSLog(@"dealloc 2");

}
@end

ARC已啟用。

僵屍似乎在產品>編輯方案上被禁用。 我正在使用xcode 6.2。 在樂器分配屏幕中,每次切換都會增加內存。

有什么問題,我找不到?

當對象(這里是其viewcontroller對象)從內存中滑出時進行dealloc調用。但是在這種情況下,您必須彼此呈現視圖控制器,從而導致僅調用viewwillappear和diddisappear。

在情節提要中,如果您想從內存中完全刪除那些視圖控制器,則應調用unwind segue

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM