2014-06-14 23 views

Odpowiedz

17

Można do niego dostęp za pomocą poniższego kodu jeśli rootViewController jest UIViewController

UIViewController *rootController=(UIViewController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController; 

Ale jeśli jest to UINavigationController można użyć poniższy kod.

UINavigationController *nav=(UINavigationController *)((AppDelegate *)[[UIApplication sharedApplication] delegate]).window.rootViewController; 
UIViewController *rootController=(UIViewController *)[nav.viewControllers objectAtIndex:0]; 
1

Swift:

let rootVC = self.window?.rootViewController

+0

Co jest 'self' w tym kontekście? – sasquatch

+0

let rootVC = UIApplication.sharedApplication(). KeyWindow? .rootViewController –

+0

Przepraszam było po prostu AppDelegate. – ingconti

0

Z konsoli:

po [[[UIApplication sharedApplication] keyWindow] rootViewController] <UINavigationController: 0x15f076c00>

Powiązane problemy