Gets the topviewcontroller of the current view
AppDelegate *appdelegate = (AppDelegate *)[UIApplication sharedApplication].delegate; UIViewController* topViewController = appdelegate.baseTabBarController.navigationController.topViewController; NSLog(@"%@",topViewController); if ([topViewController isKindOfClass:[ HomeViewController class]]) { }
Gets the Rootviewcontroller (NAV level) of the current view
-(Uiviewcontroller*) Getcurrentrootviewcontroller {Uiviewcontroller*result;//Try to find the root view controller programmically //Find the top window (that's not a alert view or other window) UIWindow*topwindow = [[uiapplicationSharedapplication] Keywindow];if(Topwindow. Windowlevel! = Uiwindowlevelnormal) {Nsarray*windows = [[uiapplicationSharedapplication] windows]; for(Topwindow in Windows) {if(Topwindow. Windowlevel= = Uiwindowlevelnormal) Break; } }UIView*rootview = [[Topwindow subviews] Objectatindex:0];IDNextresponder = [Rootview Nextresponder];if([Nextresponder iskindofclass:[UiviewcontrollerClass]]) result = Nextresponder;Else if([Topwindow Respondstoselector:@selector(Rootviewcontroller)] && Topwindow. Rootviewcontroller!=Nil) result = Topwindow. Rootviewcontroller;ElseNsassert (NO, @"Sharekit:could not find a root view controller. You can assign one manually by calling [[SHK Currenthelper] setrootviewcontroller:yourrootviewcontroller]. ");returnResult;}
IOS-Get the controller for the current view