123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- //
- // UINavigationController+EndEditing.m
- // 乐销
- //
- // Created by 隋林栋 on 2017/2/20.
- // Copyright © 2017年 ping. All rights reserved.
- //
- #import "UINavigationController+EndEditing.h"
- //vc
- //#import "FBApprovalAndLikingListVC.h"
- //#import "FBThreeNotificationListVC.h"
- //#import "FBCommentsNotificationListVC.h"
- //#import "FBAboutMineMessageListVC.h"
- //#import "FBTicketNotificationListVC.h"
- //#import "FBAttentionInformListVC.h"
- @implementation UINavigationController (EndEditing)
- #pragma mark run time
- + (void)load
- {
- method_exchangeImplementations(class_getInstanceMethod(self,@selector(pushViewController: animated:)), class_getInstanceMethod(self,@selector(sldPushViewController: animated:)));
- method_exchangeImplementations(class_getInstanceMethod(self,@selector(popViewControllerAnimated:)), class_getInstanceMethod(self,@selector(sldPopViewControllerAnimated:)));
- method_exchangeImplementations(class_getInstanceMethod(self,@selector(popToRootViewControllerAnimated:)), class_getInstanceMethod(self,@selector(sldPopToRootViewControllerAnimated:)));
- }
- - (void)sldPushViewController:(UIViewController *)viewController animated:(BOOL)animated{
- [self.view endEditing:true];
- [self sldPushViewController:viewController animated:animated];
- }
- - (void)sldPopViewControllerAnimated:(BOOL)animated{
- [self.view endEditing:true];
- // UIViewController * lastVC = self.viewControllers.lastObject;
- if (self.viewControllers.lastObject && [self.viewControllers.lastObject isKindOfClass:UIViewController.class]) {
- UIViewController * lastVC = self.viewControllers.lastObject;
- if (lastVC.blockBack) {
- lastVC.blockBack(lastVC);
- }
- }
- [self sldPopViewControllerAnimated:animated];
- }
- - (void)sldPopToRootViewControllerAnimated:(BOOL)animated{
- [self.view endEditing:true];
- [self sldPopToRootViewControllerAnimated:animated];
- }
- #pragma mark property
- - (UIViewController *)lastVC{
- return self.viewControllers.lastObject;
- }
- - (UIViewController *)lastSecondVC{
- NSArray * ary = GB_Nav.viewControllers;
- if (ary.count >= 2) {
- return ary[ary.count - 2];
- }
- return self.viewControllers.lastObject;
- }
- //跳转回root 然后跳转多个vc
- - (void)popToRootAry:(NSArray *)aryVCs animate:(BOOL)animated
- {
-
- if (aryVCs && ![aryVCs isKindOfClass:NSArray.class]) {
- return;
- }
- NSMutableArray * ary = [NSMutableArray arrayWithObject:GB_Nav.viewControllers.firstObject];
- if (aryVCs) {
- [ary addObjectsFromArray:aryVCs];
- }
- [self setViewControllers:ary animated:animated];
- }
- #pragma mark logic
- //跳转多个vc
- - (void)jumpToAry:(NSArray *)aryVCs{
- [self jumpToAry:aryVCs animate:true];
- }
- //跳转多个vc
- - (void)jumpToAry:(NSArray *)aryVCs animate:(BOOL)animated{
- if (!isAry(aryVCs)) {
- return;
- }
- NSMutableArray * ary = [NSMutableArray arrayWithArray:self.viewControllers];
- [ary addObjectsFromArray:aryVCs];
- [self setViewControllers:ary animated:animated];
- }
- //返回最后一个然后push vc
- - (void)popLastAndPushVC:(UIViewController *)vc{
- NSMutableArray * ary = [NSMutableArray arrayWithArray:self.viewControllers];
- [ary removeLastObject];
- [ary addObject:vc];
- [self setViewControllers:ary animated:true];
- }
- //返回最后一个然后pop vc
- - (void)popLastAndPopVC:(UIViewController *)vc{
- NSMutableArray * ary = [NSMutableArray arrayWithArray:self.viewControllers];
- [ary insertObject:vc atIndex:MAX(0, ary.count-1)];
- self.viewControllers = ary;
- [ary removeLastObject];
- [self setViewControllers:ary animated:true];
- }
- //往回调很多vc
- - (void)popMultiVC:(NSInteger)num{
- NSMutableArray * ary = [NSMutableArray arrayWithArray:self.viewControllers];
- if (ary.count > 0) {
- UIViewController * vc = [ary objectAtIndex:MAX(0, ary.count - 1 - num)];
- [self popToViewController:vc animated:true];
- }
-
- }
- //跳转到之前的 vc类型
- - (void)popToClass:(NSString *)className{
- NSMutableArray * ary = [NSMutableArray arrayWithArray:self.viewControllers];
- for (UIViewController * vc in ary) {
- if ([vc isKindOfClass:NSClassFromString(className)]) {
- [self popToViewController:vc animated:true];
- return;
- }
- }
- [self popViewControllerAnimated:true];
- }
- //根据名称跳转
- - (void)pushVCName:(NSString *)strClassName animated:(BOOL)animated{
- id vc = [[NSClassFromString(strClassName) alloc]init];
- [self pushViewController:vc animated:animated];
- }
- //跳转详情
- - (void)jumpToDetailVC:(NSString *)strSsort{
- if (![GlobalMethod isLoginSuccess]) return;
- // int sSort= [strSsort intValue];
- //jump to detail
- NSString * strClassName = nil;
- // if([strSsort isEqualToString:@"赞同与喜欢"]){
- // FBApprovalAndLikingListVC * detailVC = GB_Nav.viewControllers.lastObject;
- // if (detailVC && [detailVC isKindOfClass:[FBApprovalAndLikingListVC class]]) {
- // FBApprovalAndLikingListVC * detailVC = [FBApprovalAndLikingListVC new];
- // [GB_Nav popLastAndPushVC:detailVC];
- // return;
- // }
- // strClassName = @"FBApprovalAndLikingListVC";
- // }else if([strSsort isEqualToString:@"系统通知"]){
- // FBThreeNotificationListVC * detailVC = [FBThreeNotificationListVC new];
- // detailVC.type = 1;
- // [GB_Nav pushViewController:detailVC animated:true];
- // return;
- // }else if([strSsort isEqualToString:@"任务通知"]){
- // FBThreeNotificationListVC * detailVC = [FBThreeNotificationListVC new];
- // detailVC.type = 2;
- // [GB_Nav pushViewController:detailVC animated:true];
- // return;
- // }else if([strSsort isEqualToString:@"服务通知"]){
- // FBThreeNotificationListVC * detailVC = [FBThreeNotificationListVC new];
- // detailVC.type = 3;
- // [GB_Nav pushViewController:detailVC animated:true];
- // return;
- // }else if([strSsort isEqualToString:@"评论通知"]){
- // FBCommentsNotificationListVC * detailVC = GB_Nav.viewControllers.lastObject;
- // if (detailVC && [detailVC isKindOfClass:[FBCommentsNotificationListVC class]]) {
- // FBCommentsNotificationListVC * detailVC = [FBCommentsNotificationListVC new];
- // [GB_Nav popLastAndPushVC:detailVC];
- // return;
- // }
- // strClassName = @"FBCommentsNotificationListVC";
- // }else if([strSsort isEqualToString:@"@我的"]){
- // FBAboutMineMessageListVC * detailVC = GB_Nav.viewControllers.lastObject;
- // if (detailVC && [detailVC isKindOfClass:[FBAboutMineMessageListVC class]]) {
- // FBAboutMineMessageListVC * detailVC = [FBAboutMineMessageListVC new];
- // [GB_Nav popLastAndPushVC:detailVC];
- // return;
- // }
- // strClassName = @"FBAboutMineMessageListVC";
- // }else if([strSsort isEqualToString:@"船票通知"]){
- // FBTicketNotificationListVC * detailVC = GB_Nav.viewControllers.lastObject;
- // if (detailVC && [detailVC isKindOfClass:[FBTicketNotificationListVC class]]) {
- // FBTicketNotificationListVC * detailVC = [FBTicketNotificationListVC new];
- // [GB_Nav popLastAndPushVC:detailVC];
- // return;
- // }
- // strClassName = @"FBTicketNotificationListVC";
- // }else if([strSsort isEqualToString:@"关注通知"]){
- // FBAttentionInformListVC * detailVC = GB_Nav.viewControllers.lastObject;
- // if (detailVC && [detailVC isKindOfClass:[FBAttentionInformListVC class]]) {
- // FBAttentionInformListVC * detailVC = [FBAttentionInformListVC new];
- // [GB_Nav popLastAndPushVC:detailVC];
- // return;
- // }
- // strClassName = @"FBAttentionInformListVC";
- // }
- // BaseVC * vc = [NSClassFromString(strClassName) new];
- // if ([vc respondsToSelector:NSSelectorFromString(@"strID")]) {
- //// [vc setValue:identify forKeyPath:@"strID"];
- // }
- //// vc.modelModule.parentId = [strBsort doubleValue];
- //// vc.modelModule.moduleId = [strSsort doubleValue];
- // [self pushViewController:vc animated:true];
- }
- @end
|