標籤:goback super sel == dsl ima tin anim navig
Goback()方法功能:返回上一級介面,通過判斷 popViewControllerAnimated 類型是否為空白,來判斷是present還是pop出來,然後直接做了releaseSelf操作;
- (void)goBack
{
IDSLOG(@"self: %@, parent: %@", self, [self parentViewController]);
id page = [self presentingViewController];
IDSLOG(@"presenting page: %@", page);
id vc = [self.navigationController popViewControllerAnimated:YES]; IDSLOG(@"pop the = %@", vc); if (nil == vc) {
[self dismissViewControllerAnimated:YES completion:^{
}];
}
[self releaseSelf];
} releaseSelf()方法功能:用來釋放通知記憶體,和Goback()方法結合,以防忘記釋放預設通知;
- (void)releaseSelf
{
//sub class implements.
IDSLOG(@"self: %@", self);
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
PS:在每個檔案前面要加這兩句釋放記憶體的語句
- (void)dealloc
{
IDSLOG(@"dealloc - IDSGameRoomHomePage");
}
- (void)releaseSelf
{
[super releaseSelf];
} 二、我的想法 Goback這種方法,使用起來很便捷,又注意了記憶體流失,之前寫的時候,每次都要對應Push 或者 present 來寫返回操作,現在一個 [self goback] 就搞定了,我覺得這是一個比較便捷又不容易出問題的好方法。 三、思考與行動 1.Goback方法這樣寫會不會存在問題?如果有,是否思考過更好的解決辦法? 2.releaseSelf 和 dealloc 有啥區別?為什麼有dealloc還需要releaseSelf方法?合成一個方法的弊端在哪裡?
<iOS小技巧> 返回上級目錄操作Goback()方法