UINavigationController+EndEditing.m 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. //
  2. // UINavigationController+EndEditing.m
  3. // 乐销
  4. //
  5. // Created by 隋林栋 on 2017/2/20.
  6. // Copyright © 2017年 ping. All rights reserved.
  7. //
  8. #import "UINavigationController+EndEditing.h"
  9. //vc
  10. //#import "FBApprovalAndLikingListVC.h"
  11. //#import "FBThreeNotificationListVC.h"
  12. //#import "FBCommentsNotificationListVC.h"
  13. //#import "FBAboutMineMessageListVC.h"
  14. //#import "FBTicketNotificationListVC.h"
  15. //#import "FBAttentionInformListVC.h"
  16. @implementation UINavigationController (EndEditing)
  17. #pragma mark run time
  18. + (void)load
  19. {
  20. method_exchangeImplementations(class_getInstanceMethod(self,@selector(pushViewController: animated:)), class_getInstanceMethod(self,@selector(sldPushViewController: animated:)));
  21. method_exchangeImplementations(class_getInstanceMethod(self,@selector(popViewControllerAnimated:)), class_getInstanceMethod(self,@selector(sldPopViewControllerAnimated:)));
  22. method_exchangeImplementations(class_getInstanceMethod(self,@selector(popToRootViewControllerAnimated:)), class_getInstanceMethod(self,@selector(sldPopToRootViewControllerAnimated:)));
  23. }
  24. - (void)sldPushViewController:(UIViewController *)viewController animated:(BOOL)animated{
  25. [self.view endEditing:true];
  26. [self sldPushViewController:viewController animated:animated];
  27. }
  28. - (void)sldPopViewControllerAnimated:(BOOL)animated{
  29. [self.view endEditing:true];
  30. // UIViewController * lastVC = self.viewControllers.lastObject;
  31. if (self.viewControllers.lastObject && [self.viewControllers.lastObject isKindOfClass:UIViewController.class]) {
  32. UIViewController * lastVC = self.viewControllers.lastObject;
  33. if (lastVC.blockBack) {
  34. lastVC.blockBack(lastVC);
  35. }
  36. }
  37. [self sldPopViewControllerAnimated:animated];
  38. }
  39. - (void)sldPopToRootViewControllerAnimated:(BOOL)animated{
  40. [self.view endEditing:true];
  41. [self sldPopToRootViewControllerAnimated:animated];
  42. }
  43. #pragma mark property
  44. - (UIViewController *)lastVC{
  45. return self.viewControllers.lastObject;
  46. }
  47. - (UIViewController *)lastSecondVC{
  48. NSArray * ary = GB_Nav.viewControllers;
  49. if (ary.count >= 2) {
  50. return ary[ary.count - 2];
  51. }
  52. return self.viewControllers.lastObject;
  53. }
  54. //跳转回root 然后跳转多个vc
  55. - (void)popToRootAry:(NSArray *)aryVCs animate:(BOOL)animated
  56. {
  57. if (aryVCs && ![aryVCs isKindOfClass:NSArray.class]) {
  58. return;
  59. }
  60. NSMutableArray * ary = [NSMutableArray arrayWithObject:GB_Nav.viewControllers.firstObject];
  61. if (aryVCs) {
  62. [ary addObjectsFromArray:aryVCs];
  63. }
  64. [self setViewControllers:ary animated:animated];
  65. }
  66. #pragma mark logic
  67. //跳转多个vc
  68. - (void)jumpToAry:(NSArray *)aryVCs{
  69. [self jumpToAry:aryVCs animate:true];
  70. }
  71. //跳转多个vc
  72. - (void)jumpToAry:(NSArray *)aryVCs animate:(BOOL)animated{
  73. if (!isAry(aryVCs)) {
  74. return;
  75. }
  76. NSMutableArray * ary = [NSMutableArray arrayWithArray:self.viewControllers];
  77. [ary addObjectsFromArray:aryVCs];
  78. [self setViewControllers:ary animated:animated];
  79. }
  80. //返回最后一个然后push vc
  81. - (void)popLastAndPushVC:(UIViewController *)vc{
  82. NSMutableArray * ary = [NSMutableArray arrayWithArray:self.viewControllers];
  83. [ary removeLastObject];
  84. [ary addObject:vc];
  85. [self setViewControllers:ary animated:true];
  86. }
  87. //返回最后一个然后pop vc
  88. - (void)popLastAndPopVC:(UIViewController *)vc{
  89. NSMutableArray * ary = [NSMutableArray arrayWithArray:self.viewControllers];
  90. [ary insertObject:vc atIndex:MAX(0, ary.count-1)];
  91. self.viewControllers = ary;
  92. [ary removeLastObject];
  93. [self setViewControllers:ary animated:true];
  94. }
  95. //往回调很多vc
  96. - (void)popMultiVC:(NSInteger)num{
  97. NSMutableArray * ary = [NSMutableArray arrayWithArray:self.viewControllers];
  98. if (ary.count > 0) {
  99. UIViewController * vc = [ary objectAtIndex:MAX(0, ary.count - 1 - num)];
  100. [self popToViewController:vc animated:true];
  101. }
  102. }
  103. //跳转到之前的 vc类型
  104. - (void)popToClass:(NSString *)className{
  105. NSMutableArray * ary = [NSMutableArray arrayWithArray:self.viewControllers];
  106. for (UIViewController * vc in ary) {
  107. if ([vc isKindOfClass:NSClassFromString(className)]) {
  108. [self popToViewController:vc animated:true];
  109. return;
  110. }
  111. }
  112. [self popViewControllerAnimated:true];
  113. }
  114. //根据名称跳转
  115. - (void)pushVCName:(NSString *)strClassName animated:(BOOL)animated{
  116. id vc = [[NSClassFromString(strClassName) alloc]init];
  117. [self pushViewController:vc animated:animated];
  118. }
  119. //跳转详情
  120. - (void)jumpToDetailVC:(NSString *)strSsort{
  121. if (![GlobalMethod isLoginSuccess]) return;
  122. // int sSort= [strSsort intValue];
  123. //jump to detail
  124. NSString * strClassName = nil;
  125. // if([strSsort isEqualToString:@"赞同与喜欢"]){
  126. // FBApprovalAndLikingListVC * detailVC = GB_Nav.viewControllers.lastObject;
  127. // if (detailVC && [detailVC isKindOfClass:[FBApprovalAndLikingListVC class]]) {
  128. // FBApprovalAndLikingListVC * detailVC = [FBApprovalAndLikingListVC new];
  129. // [GB_Nav popLastAndPushVC:detailVC];
  130. // return;
  131. // }
  132. // strClassName = @"FBApprovalAndLikingListVC";
  133. // }else if([strSsort isEqualToString:@"系统通知"]){
  134. // FBThreeNotificationListVC * detailVC = [FBThreeNotificationListVC new];
  135. // detailVC.type = 1;
  136. // [GB_Nav pushViewController:detailVC animated:true];
  137. // return;
  138. // }else if([strSsort isEqualToString:@"任务通知"]){
  139. // FBThreeNotificationListVC * detailVC = [FBThreeNotificationListVC new];
  140. // detailVC.type = 2;
  141. // [GB_Nav pushViewController:detailVC animated:true];
  142. // return;
  143. // }else if([strSsort isEqualToString:@"服务通知"]){
  144. // FBThreeNotificationListVC * detailVC = [FBThreeNotificationListVC new];
  145. // detailVC.type = 3;
  146. // [GB_Nav pushViewController:detailVC animated:true];
  147. // return;
  148. // }else if([strSsort isEqualToString:@"评论通知"]){
  149. // FBCommentsNotificationListVC * detailVC = GB_Nav.viewControllers.lastObject;
  150. // if (detailVC && [detailVC isKindOfClass:[FBCommentsNotificationListVC class]]) {
  151. // FBCommentsNotificationListVC * detailVC = [FBCommentsNotificationListVC new];
  152. // [GB_Nav popLastAndPushVC:detailVC];
  153. // return;
  154. // }
  155. // strClassName = @"FBCommentsNotificationListVC";
  156. // }else if([strSsort isEqualToString:@"@我的"]){
  157. // FBAboutMineMessageListVC * detailVC = GB_Nav.viewControllers.lastObject;
  158. // if (detailVC && [detailVC isKindOfClass:[FBAboutMineMessageListVC class]]) {
  159. // FBAboutMineMessageListVC * detailVC = [FBAboutMineMessageListVC new];
  160. // [GB_Nav popLastAndPushVC:detailVC];
  161. // return;
  162. // }
  163. // strClassName = @"FBAboutMineMessageListVC";
  164. // }else if([strSsort isEqualToString:@"船票通知"]){
  165. // FBTicketNotificationListVC * detailVC = GB_Nav.viewControllers.lastObject;
  166. // if (detailVC && [detailVC isKindOfClass:[FBTicketNotificationListVC class]]) {
  167. // FBTicketNotificationListVC * detailVC = [FBTicketNotificationListVC new];
  168. // [GB_Nav popLastAndPushVC:detailVC];
  169. // return;
  170. // }
  171. // strClassName = @"FBTicketNotificationListVC";
  172. // }else if([strSsort isEqualToString:@"关注通知"]){
  173. // FBAttentionInformListVC * detailVC = GB_Nav.viewControllers.lastObject;
  174. // if (detailVC && [detailVC isKindOfClass:[FBAttentionInformListVC class]]) {
  175. // FBAttentionInformListVC * detailVC = [FBAttentionInformListVC new];
  176. // [GB_Nav popLastAndPushVC:detailVC];
  177. // return;
  178. // }
  179. // strClassName = @"FBAttentionInformListVC";
  180. // }
  181. // BaseVC * vc = [NSClassFromString(strClassName) new];
  182. // if ([vc respondsToSelector:NSSelectorFromString(@"strID")]) {
  183. //// [vc setValue:identify forKeyPath:@"strID"];
  184. // }
  185. //// vc.modelModule.parentId = [strBsort doubleValue];
  186. //// vc.modelModule.moduleId = [strSsort doubleValue];
  187. // [self pushViewController:vc animated:true];
  188. }
  189. @end