<iOS小技巧> 返回上級目錄操作Goback()方法

來源:互聯網
上載者:User

標籤: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()方法

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.