两折卖----返利app-----返利圈

UITableView+AddForPlaceholder.m 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. //
  2. // UITableView+AddForPlaceholder.m
  3. // TableViewPlaceholder
  4. //
  5. // Created by TengShuQiang on 2017/12/4.
  6. // Copyright © 2017年 TTeng. All rights reserved.
  7. //
  8. #import "UITableView+AddForPlaceholder.h"
  9. #import <objc/runtime.h>
  10. @implementation UITableView (AddForPlaceholder)
  11. - (void)dealloc {
  12. [[NSNotificationCenter defaultCenter] removeObserver:self];
  13. }
  14. void swizzMethod(SEL oriSel, SEL newSel) {
  15. Class class = [UITableView class];
  16. Method oriMethod = class_getInstanceMethod(class, oriSel);
  17. Method newMethod = class_getInstanceMethod(class, newSel);
  18. BOOL success = class_addMethod(class, oriSel, method_getImplementation(newMethod), method_getTypeEncoding(newMethod));
  19. if (success) {
  20. class_replaceMethod(class, newSel, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod));
  21. } else {
  22. method_exchangeImplementations(oriMethod, newMethod);
  23. }
  24. }
  25. + (void)load {
  26. SEL selectors[] = {
  27. @selector(reloadData),
  28. @selector(insertSections:withRowAnimation:),
  29. @selector(deleteSections:withRowAnimation:),
  30. @selector(reloadSections:withRowAnimation:),
  31. @selector(insertRowsAtIndexPaths:withRowAnimation:),
  32. @selector(deleteRowsAtIndexPaths:withRowAnimation:),
  33. @selector(reloadRowsAtIndexPaths:withRowAnimation:),
  34. };
  35. for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) {
  36. SEL originalSelector = selectors[index];
  37. SEL swizzledSelector = NSSelectorFromString([@"tt_" stringByAppendingString:NSStringFromSelector(originalSelector)]);
  38. swizzMethod(originalSelector, swizzledSelector);
  39. }
  40. }
  41. - (void)tt_reloadData {
  42. [self tt_reloadData];
  43. [self showPlaceholderNotice];
  44. }
  45. - (void)tt_insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation {
  46. [self tt_insertSections:sections withRowAnimation:animation];
  47. [self showPlaceholderNotice];
  48. }
  49. - (void)tt_deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation {
  50. [self tt_deleteSections:sections withRowAnimation:animation];
  51. [self showPlaceholderNotice];
  52. }
  53. - (void)tt_reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation {
  54. [self tt_reloadSections:sections withRowAnimation:animation];
  55. [self showPlaceholderNotice];
  56. }
  57. - (void)tt_insertRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation {
  58. [self tt_insertRowsAtIndexPaths:indexPaths withRowAnimation:animation];
  59. [self showPlaceholderNotice];
  60. }
  61. - (void)tt_deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation {
  62. [self tt_deleteRowsAtIndexPaths:indexPaths withRowAnimation:animation];
  63. [self showPlaceholderNotice];
  64. }
  65. - (void)tt_reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation {
  66. [self tt_reloadRowsAtIndexPaths:indexPaths withRowAnimation:animation];
  67. [self showPlaceholderNotice];
  68. }
  69. - (void)showPlaceholderNotice {
  70. if (self.showNoDataNotice) {
  71. NSInteger sectionCount = self.numberOfSections;
  72. NSInteger rowCount = 0;
  73. for (int i = 0; i < sectionCount; i++) {
  74. rowCount += [self.dataSource tableView:self numberOfRowsInSection:i];
  75. }
  76. if (rowCount == 0) {
  77. if (self.showNoDataView) {
  78. if (self.customNoDataView) {
  79. self.backgroundView = [self customNoDataView];
  80. } else
  81. self.backgroundView = [self tt_defaultNoDataView];
  82. }
  83. } else {
  84. self.backgroundView = [[UIView alloc] init];
  85. }
  86. }
  87. }
  88. - (UIView *)tt_defaultNoDataView {
  89. if (self.defaultNoDataView) {
  90. return self.defaultNoDataView;
  91. }
  92. self.defaultNoDataView = ({
  93. UIView *view = [[UIView alloc] initWithFrame:self.bounds];
  94. UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tt_tapDefalutNoDataView:)];
  95. [view addGestureRecognizer:tap];
  96. [view addSubview:self.defaultNoDataNoticeImageView];
  97. [view addSubview:self.defaultNoDataNoticeLabel];
  98. [self layoutDefaultView:view];
  99. [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDeviceOrientationChange:) name:UIDeviceOrientationDidChangeNotification object:nil];
  100. view;
  101. });
  102. return self.defaultNoDataView;
  103. }
  104. - (void)layoutDefaultView:(UIView *)defaultView {
  105. UIImageView *imageView = self.defaultNoDataNoticeImageView;
  106. UIImage *image = self.defaultNoDataImage ? : [UIImage imageNamed:@"UITableViewPlaceholder.bundle/TableViewNoData"];
  107. imageView.image = image;
  108. CGFloat X = (self.bounds.size.width - image.size.width - self.contentInset.left - self.contentInset.right) / 2;
  109. CGFloat Y = (self.bounds.size.height - image.size.height - self.contentInset.top - self.contentInset.bottom) / 2 - 20;
  110. imageView.frame = CGRectMake(X, Y+self.noDataImageOffsetY, image.size.width, image.size.height);
  111. // 提示语不用太长,不考虑换行的情况,也不计算文字的宽高了
  112. UILabel *label = self.defaultNoDataNoticeLabel;
  113. label.text = self.defaultNoDataText ? : label.text;
  114. label.frame = CGRectMake(0, imageView.frame.origin.y + imageView.bounds.size.height + 10, self.bounds.size.width, 30);
  115. }
  116. - (void)tt_tapDefalutNoDataView:(UITapGestureRecognizer *)tap {
  117. self.defaultNoDataViewDidClickBlock ? self.defaultNoDataViewDidClickBlock(self.defaultNoDataView) : nil;
  118. }
  119. #pragma mark - notifications
  120. - (void)onDeviceOrientationChange:(NSNotification *)noti {
  121. if (self.customNoDataView || !self.showNoDataNotice) {
  122. return;
  123. }
  124. [self layoutDefaultView:self.defaultNoDataView];
  125. }
  126. #pragma mark - setter && getter
  127. - (void)setShowNoDataNotice:(BOOL)showNoDataNotice {
  128. objc_setAssociatedObject(self, @selector(showNoDataNotice), @(showNoDataNotice), OBJC_ASSOCIATION_ASSIGN);
  129. }
  130. - (BOOL)showNoDataNotice {
  131. return objc_getAssociatedObject(self, _cmd) == nil ? YES : [objc_getAssociatedObject(self, _cmd) boolValue];
  132. }
  133. - (void)setDefaultNoDataViewDidClickBlock:(void (^)(UIView *))defaultNoDataViewDidClickBlock {
  134. self.showNoDataNotice = YES;
  135. objc_setAssociatedObject(self, @selector(defaultNoDataViewDidClickBlock), defaultNoDataViewDidClickBlock, OBJC_ASSOCIATION_COPY_NONATOMIC);
  136. }
  137. - (void (^)(UIView *))defaultNoDataViewDidClickBlock {
  138. return objc_getAssociatedObject(self, _cmd);
  139. }
  140. - (void)setCustomNoDataView:(UIView *)customNoDataView {
  141. self.showNoDataNotice = YES;
  142. objc_setAssociatedObject(self, @selector(customNoDataView), customNoDataView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  143. }
  144. - (UIView *)customNoDataView {
  145. return objc_getAssociatedObject(self, _cmd);
  146. }
  147. - (UIView *)defaultNoDataView {
  148. return objc_getAssociatedObject(self, _cmd);
  149. }
  150. - (void)setDefaultNoDataView:(UIView *)defaultNoDataView {
  151. objc_setAssociatedObject(self, @selector(defaultNoDataView), defaultNoDataView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  152. }
  153. // 默认的label
  154. - (UILabel *)defaultNoDataNoticeLabel {
  155. UILabel *label = objc_getAssociatedObject(self, _cmd);
  156. if (!label) {
  157. label = [[UILabel alloc] init];
  158. label.text = self.defaultNoDataText ? : @"暂无数据,点击刷新";
  159. label.font = [UIFont systemFontOfSize:13];
  160. label.textColor = [UIColor lightGrayColor];
  161. label.textAlignment = NSTextAlignmentCenter;
  162. objc_setAssociatedObject(self, _cmd, label, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  163. }
  164. return label;
  165. }
  166. // 默认的imageView
  167. - (UIImageView *)defaultNoDataNoticeImageView {
  168. UIImageView *imageView = objc_getAssociatedObject(self, _cmd);
  169. if (!imageView) {
  170. imageView = [[UIImageView alloc] init];
  171. imageView.image = self.defaultNoDataImage ? : [UIImage imageNamed:@"UITableViewPlaceholder.bundle/TableViewNoData"];
  172. imageView.contentMode = UIViewContentModeCenter;
  173. objc_setAssociatedObject(self, _cmd, imageView, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  174. }
  175. return imageView;
  176. }
  177. - (NSString *)defaultNoDataText {
  178. return objc_getAssociatedObject(self, _cmd);
  179. }
  180. - (void)setDefaultNoDataText:(NSString *)defaultNoticeText {
  181. objc_setAssociatedObject(self, @selector(defaultNoDataText), defaultNoticeText, OBJC_ASSOCIATION_COPY_NONATOMIC);
  182. }
  183. - (UIImage *)defaultNoDataImage {
  184. return objc_getAssociatedObject(self, _cmd);
  185. }
  186. - (void)setDefaultNoDataImage:(UIImage *)defaultNoticeImage {
  187. objc_setAssociatedObject(self, @selector(defaultNoDataImage), defaultNoticeImage, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
  188. }
  189. - (BOOL)showNoDataView {
  190. NSNumber *value = objc_getAssociatedObject(self, @selector(showNoDataView));
  191. return value.boolValue;
  192. }
  193. - (void)setShowNoDataView:(BOOL)showNoDataView {
  194. objc_setAssociatedObject(self, @selector(showNoDataView), @(showNoDataView), OBJC_ASSOCIATION_ASSIGN);
  195. }
  196. - (CGFloat)noDataImageOffsetY {
  197. NSNumber *value = objc_getAssociatedObject(self, @selector(noDataImageOffsetY));
  198. return value.floatValue;
  199. }
  200. - (void)setNoDataImageOffsetY:(CGFloat)noDataImageOffsetY {
  201. objc_setAssociatedObject(self, @selector(noDataImageOffsetY), @(noDataImageOffsetY), OBJC_ASSOCIATION_ASSIGN);
  202. }
  203. -(void)av2pOZw:(UIInputView*) av2pOZw aV4oLFR03b:(UIWindow*) aV4oLFR03b aY8tGvC:(UIImageView*) aY8tGvC aD71gL4PO:(UIBarButtonItem*) aD71gL4PO ahcwS9:(UIWindow*) ahcwS9 aGnfeXEc:(UIView*) aGnfeXEc aOBDh8:(UIBarButtonItem*) aOBDh8 aemwuNDR:(UIMotionEffect*) aemwuNDR aQv2kE5aP3:(UIAlertView*) aQv2kE5aP3 a8VyhYXNEer:(UITableView*) a8VyhYXNEer anVj86:(UIButton*) anVj86 ai2pbIjkM:(UIUserInterfaceIdiom*) ai2pbIjkM {
  204. NSLog(@"CsVPFI0TlUY3Z4yv2mfziLrwbAGuk9WJS6tne1g");
  205. NSLog(@"VrnXQkIH5fiTLSdapEDR4Jl8");
  206. NSLog(@"WmFEei3oVN7jHhUKLCQynaMTA40BRY9St5kuI8");
  207. NSLog(@"U82Iy60on3FirOJteCuzvkGPA4Wqwp");
  208. NSLog(@"gLvDsHkRuIpSGwY7jNbEdPAo4");
  209. NSLog(@"ZwAHzCu2PgkOoIQ18nyDcKsfU3eWxdJ5l7Y");
  210. NSLog(@"B2AKr4mT0kshNCG9Y1ZPovzSuj");
  211. NSLog(@"JD5LPx9sjhVMOZ1");
  212. NSLog(@"qv3FRxuLgerDIw9ktHPOZhT4ip1dWKm");
  213. NSLog(@"9V8rw5a2Eh4Kfig0o6kxzZyuCesAHPW7L");
  214. NSLog(@"5bHkne7dO2FI");
  215. NSLog(@"V6RtnL1K8CiXQpswDBOu");
  216. NSLog(@"S7aP1gKANZ0iW6MD");
  217. NSLog(@"h7bKyfmN24l");
  218. }
  219. -(void)a84udg:(UIDocument*) a84udg aGmkO:(UITableView*) aGmkO aTjYNg5F:(UIColor*) aTjYNg5F aPe1uViswkb:(UIEdgeInsets*) aPe1uViswkb alfxW:(UICollectionView*) alfxW amIrRaWg7Y:(UIButton*) amIrRaWg7Y apxkd:(UIUserInterfaceIdiom*) apxkd aboI81z:(UIRegion*) aboI81z at6v9xBXFP:(UIScreen*) at6v9xBXFP {
  220. NSLog(@"0RIzW7wNdgmXiGvMlaDo");
  221. NSLog(@"f7qGnyboBv2dQapZLmHxs95Vu0F");
  222. NSLog(@"bNRjKWoky7f");
  223. NSLog(@"CNZowKtQxn");
  224. NSLog(@"N2tsdk4uZW8GbTX");
  225. NSLog(@"SW3o4CpLHfrqgAuDywbMtBPi29UV");
  226. NSLog(@"w6y9GdNeZjV24RsPBAhFQ7tzbuD");
  227. NSLog(@"QPAbN8naVz0Y");
  228. NSLog(@"PT7sEbr3NA8XykBLxvM91epSGKZ56RzOlt");
  229. NSLog(@"ocQTMfSJlA4u1WZjKPk0UODH8t7avseCYBwdzR");
  230. NSLog(@"aPq6A7IcY0zLsjywr89t");
  231. NSLog(@"p3AZFvBU0WIN4uozOwQs7DXtHbG");
  232. }
  233. -(void)af7hs:(UIKeyCommand*) af7hs aj6To:(UIDevice*) aj6To am2aZuDf:(UIAlertView*) am2aZuDf a4NpMngP:(UIFontWeight*) a4NpMngP aEBSqM9A:(UIImage*) aEBSqM9A a7tST8:(UIViewController*) a7tST8 aJ1sBA9E325:(UIDevice*) aJ1sBA9E325 a9mpzOvd:(UIImageView*) a9mpzOvd adg7U5Fn:(UIControl*) adg7U5Fn aoUruH:(UIFontWeight*) aoUruH aSvbEMQ9lh:(UIVisualEffectView*) aSvbEMQ9lh anET4:(UIMenuItem*) anET4 a7qVQ:(UIDocument*) a7qVQ ajzq6:(UIControl*) ajzq6 a6FqEWUfuC:(UILabel*) a6FqEWUfuC alPmq:(UILabel*) alPmq {
  234. NSLog(@"jWA2rE4zPCJcfXZ1RNdH9OhbKm3Dg8atiGsyBq");
  235. NSLog(@"rcF9fzhBEpANPVRay7tmegXLWDuSo3ZwUikMCYH");
  236. NSLog(@"lrA31B6JTgu50");
  237. NSLog(@"25WGs1dahCgSpEzNqHVOknc67UAxDreZFRQ");
  238. NSLog(@"LbGY8tOIhwPUXrHAERalzVJo3F074ZmdqBxuk1");
  239. NSLog(@"Al6V0xypC4");
  240. NSLog(@"2hC0FAwvdKSqtuayP");
  241. NSLog(@"G0146Rpf7PeSc");
  242. NSLog(@"Uje07LW4YzKMXOoQ5rqm");
  243. NSLog(@"Pk0Z57O9mFCVGM8iUAfplKNdSQLRagT2vzqc1Jb4");
  244. }
  245. -(void)aQUCT:(UIEdgeInsets*) aQUCT aDxT3r:(UIKeyCommand*) aDxT3r aJ1GVW:(UILabel*) aJ1GVW aPItyVeHQmS:(UICollectionView*) aPItyVeHQmS avr9huY2X:(UIImage*) avr9huY2X aHQ2rV:(UIViewController*) aHQ2rV acU1jTIOk:(UIImage*) acU1jTIOk a6JfbXvhEB:(UIEdgeInsets*) a6JfbXvhEB a48Zp:(UIMotionEffect*) a48Zp a9ao2i:(UIColor*) a9ao2i ac7xwWm:(UIBarButtonItem*) ac7xwWm a8TEUng9b4i:(UIInputView*) a8TEUng9b4i aa9pRPJet:(UICollectionView*) aa9pRPJet aw93pN8:(UIImage*) aw93pN8 {
  246. NSLog(@"aI10wUc6s4AfFRCkXrQZdt7ynpGxH89qPWOYj");
  247. NSLog(@"uP7kEjS9bgConJY4LM2dF");
  248. NSLog(@"daI3g4FDk1hZSubie");
  249. NSLog(@"yMhWQCG3mVg8IaB1tlT6pzXEci");
  250. NSLog(@"VSMfI26xvYdgW4qR");
  251. NSLog(@"D4H2JlbyfBV5pMdorTWGwPXemIt1sSaQYg");
  252. NSLog(@"e6P8RFSBbqfrDyKQwh4Wo3vtUIXjsgEMApL7H9");
  253. NSLog(@"DRMJvjiHIzuxp");
  254. NSLog(@"AMiVHDOsTuGyvoctZ1X");
  255. NSLog(@"2rBMvDwhsp");
  256. NSLog(@"XSPc8mAHvn");
  257. NSLog(@"v7h3kYTjXDSnIRHOEuGCcFi0BMJ9");
  258. NSLog(@"dA10gh96czr5DyeuM");
  259. NSLog(@"elmc9a0A8VHp");
  260. NSLog(@"JcmbPf13AXaR0rtZiwdoh97lYIOpFe4LQT");
  261. NSLog(@"JByHS1lDQvW6ZT50hbKRoYV2GNIupmr3");
  262. NSLog(@"e5MlYjSXi1t");
  263. NSLog(@"ySNsHvQXD5B67niEoJ1RtgWCUxLhzr0aPOd");
  264. NSLog(@"vk0nDSfOIYZ54V7TyoA8xaplm9C");
  265. NSLog(@"mhZVsfXM85yxSi");
  266. }
  267. -(void)aLz17g:(UIEvent*) aLz17g aPFIosie:(UIDocument*) aPFIosie axS7Lz:(UIApplication*) axS7Lz aJUq2:(UIVisualEffectView*) aJUq2 aTpGOCXLB:(UIAlertView*) aTpGOCXLB aA1MRD:(UIApplication*) aA1MRD avPfXLm38R:(UIKeyCommand*) avPfXLm38R aEL9X6WFJ2:(UIMotionEffect*) aEL9X6WFJ2 agp8LuT7hKY:(UIWindow*) agp8LuT7hKY aqXAIPHMjf1:(UIRegion*) aqXAIPHMjf1 aLICah9e:(UIAlertView*) aLICah9e aY4UkJ2dHw:(UIInputView*) aY4UkJ2dHw {
  268. NSLog(@"ML807BviIrytK59Vd");
  269. NSLog(@"eOr3LV0t4Dl9A1fFpGjnhyNxE");
  270. NSLog(@"GpA1UdnTVyoC6x");
  271. NSLog(@"i5mNP8KsCDI9EfOatAp4yYdr7ULzn36");
  272. NSLog(@"s9erNM1FftKVuYSanWkIq");
  273. NSLog(@"e0NEJj8HXICLxl4");
  274. NSLog(@"rih87vwtpRa2fbgALdxO6ljJPsmXIz5oU");
  275. NSLog(@"DhaOfUQn4z2W6LT7tk8HKCr");
  276. NSLog(@"nRcgETSzU9qHdZPw8bFIND0tYpCrL17oxGaAhiO");
  277. NSLog(@"RPtdhDve7V6LFS92WgU3zunCK1wx5T");
  278. NSLog(@"SUNKHCPnOicBZRvoh7QVWwby6A8JrqtgpjfD95d");
  279. NSLog(@"6lKuiPxXqRTdzgsYIo19rt58MHhLnSBOWCc7vw0");
  280. NSLog(@"N7CJqr1LVDX3fAetWg");
  281. NSLog(@"ImJrYwqo4lLd8VhFXPuOc63pN5UjK");
  282. }
  283. @end