簡體   English   中英

使用ARC釋放與UITabBarController關聯的ViewController

[英]Release ViewControllers Associated with UITabBarController with ARC

我正在以下結構的應用程序中工作

-UINavigationController (MAIN NAVIGATION CONTROLLER)
--UIViewController
---UITabBarController
     -- UINavigationController1
     ---- UITableViewController1

     -- UINavigationController2
     ---- UITableViewController2

     -- UIViewController ( Logout Button is in this Controller )

現在我在調用下面的方法來注銷用戶到First ViewController

[self.navigationController popToRootViewControllerAnimated:YES];

在這里self.navigationController =(MAIN NAVIGATION CONTROLLER)

但是此代碼不起作用,無法在控制器下取消初始化。

-- UINavigationController1
---- UITableViewController1

-- UINavigationController2
---- UITableViewController2

我正在使用ARC,因此無法為所有控制器調用釋放方法,因此如何實現此目的。

更新

這是我的推送代碼:

//Property Declare in AppDelegate
@property (nonatomic,weak) UITabBarController *tabBarControllerRef;

// Below code Written in RootViewController of (MAIN NAVIGATION CONTROLLER)
-(void)moveToContentScreen { 
AppDelegate *delegateRef = (AppDelegate *) [UIApplication sharedApplication].delegate;
delegateRef.tabBarControllerRef = [self.storyboard instantiateViewControllerWithIdentifier:@"tabbarReference"];
if (delegateRef.tabBarControllerRef) {
    [self.navigationController pushViewController:delegateRef.tabBarControllerRef animated:YES];
}
}

幾乎可以肯定的是,您有一個強大的參考周期。 兩個(或更多)對象,每個對象在一個循環中都擁有對其他對象的強引用,因此不能刪除它們。 例如,UITabBarController是否對其封閉視圖有很強的引用? 如果是這樣,請使至少一個參考值變弱以破壞周期。

如果通過查看並不清楚哪些對象可能相互循環引用,則可以使用Instruments嘗試查找它們; 這里有一個很棒的教程 ,“強參考循環”部分幾乎完全討論了這種問題。

UIViewController如何顯示UITabBarController 孩子/父母? 如果是這樣,則看起來第一個UIViewController視圖控制器仍保留對UITabBarController的引用。 從圖UIViewController ,初始的UINavigationController似乎只有一個推送的UIViewController ,而根是一個。

暫無
暫無

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

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