在做輪播圖的時候,有點輪播圖展示的是廣告,有的是活動,等等還有其他的
當前點擊某個輪播的時候要跳轉到不同的控制器,點擊事件是在控制器寫的,為了避免控制器代碼過多,顯示的臃腫
我創建了一個UIWindow的分類,暫且叫Model (GetCurrentVC)
谷歌還有很多方法,我這個方法親測有效,其他方法后續再測試
一:
@interfaceUIWindow (GetCurrentVC)
- (UIViewController*)getCurrentVC;
@end
二:
#import"UIWindow+GetCurrentVC.h"
@implementationUIWindow (GetCurrentVC)
-? (UIViewController*)getCurrentVC {
UIViewController*result =nil;
UIWindow* window = [[UIApplicationsharedApplication]keyWindow];
if(window.windowLevel!=UIWindowLevelNormal)
{
NSArray*windows = [[UIApplicationsharedApplication]windows];
for(UIWindow* tmpWininwindows)
{
if(tmpWin.windowLevel==UIWindowLevelNormal)
{
window = tmpWin;
break;
}
}
}
UIView*frontView = [[windowsubviews]objectAtIndex:0];
idnextResponder = [frontViewnextResponder];
if([nextResponderisKindOfClass:[UIViewControllerclass]])
result = nextResponder;
else
result = window.rootViewController;
returnresult;
}
@end