Re: [問題] 程式的流程-viewController想call supe …

看板MacDev作者 (zonble)時間15年前 (2010/07/24 04:18), 編輯推噓1(100)
留言1則, 1人參與, 最新討論串1/3 (看更多)
※ 引述《Gsus (肉元,吉米,助教)》之銘言: : 我要怎麼在a/bViewController中remove自己 ? : 並且讓appDelegate去add tabBarController.view ? : 我知道的方法有利用protocol,在appDelegate中實作protocol的method : 並且在a/bViewController中call appDelegate中的protocol method : 但是我想問有沒有其他的方法? 聽起來你想要做的事情就是,你想要把 applcation delegate 裡頭 定義的那個 window 上面換不同的內容,原本是 FirstViewContoller 的 view,把這個 view 拿掉,然後換成 tabBarController 的 view 我假設 firstViewController 與 tabBarController 都是 AppDelegate 的成員變數,那麼,先在 AppDelegate 裡頭弄一個 method - (void)useTabBarView { [firstViewController viewWillDisappear:YES]; [firstViewController.view removeFromSuperView]; [firstViewController viewDidDisappear:YES]; [tabBarController viewWillAppear:YES]; [window addSubview:tabBarController.view]; [tabBarController viewDidAppear:YES]; // 高興的話還可以加上 UIVew animation… } 然後,我們在 a/bViewController 要拿到 AppDelegate 物件,就可以 呼叫這個 method 了。 1. 在 a/vViewController 裡頭要 inlucde AppDelegate 的 header 2. 大概是這樣寫 AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; [appDelegate useTabBarView]; 我好像在前面哪邊也有提到怎樣拿到 AppDelegate 的 instance。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 114.42.191.15

07/24 09:40, , 1F
感謝! 我已經試成功了~
07/24 09:40, 1F
文章代碼(AID): #1CIVZvK1 (MacDev)
文章代碼(AID): #1CIVZvK1 (MacDev)