// // UITableView+AddForPlaceholder.m // TableViewPlaceholder // // Created by TengShuQiang on 2017/12/4. // Copyright © 2017年 TTeng. All rights reserved. // #import "UITableView+AddForPlaceholder.h" #import @implementation UITableView (AddForPlaceholder) - (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self]; } void swizzMethod(SEL oriSel, SEL newSel) { Class class = [UITableView class]; Method oriMethod = class_getInstanceMethod(class, oriSel); Method newMethod = class_getInstanceMethod(class, newSel); BOOL success = class_addMethod(class, oriSel, method_getImplementation(newMethod), method_getTypeEncoding(newMethod)); if (success) { class_replaceMethod(class, newSel, method_getImplementation(oriMethod), method_getTypeEncoding(oriMethod)); } else { method_exchangeImplementations(oriMethod, newMethod); } } + (void)load { SEL selectors[] = { @selector(reloadData), @selector(insertSections:withRowAnimation:), @selector(deleteSections:withRowAnimation:), @selector(reloadSections:withRowAnimation:), @selector(insertRowsAtIndexPaths:withRowAnimation:), @selector(deleteRowsAtIndexPaths:withRowAnimation:), @selector(reloadRowsAtIndexPaths:withRowAnimation:), }; for (NSUInteger index = 0; index < sizeof(selectors) / sizeof(SEL); ++index) { SEL originalSelector = selectors[index]; SEL swizzledSelector = NSSelectorFromString([@"tt_" stringByAppendingString:NSStringFromSelector(originalSelector)]); swizzMethod(originalSelector, swizzledSelector); } } - (void)tt_reloadData { [self tt_reloadData]; [self showPlaceholderNotice]; } - (void)tt_insertSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation { [self tt_insertSections:sections withRowAnimation:animation]; [self showPlaceholderNotice]; } - (void)tt_deleteSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation { [self tt_deleteSections:sections withRowAnimation:animation]; [self showPlaceholderNotice]; } - (void)tt_reloadSections:(NSIndexSet *)sections withRowAnimation:(UITableViewRowAnimation)animation { [self tt_reloadSections:sections withRowAnimation:animation]; [self showPlaceholderNotice]; } - (void)tt_insertRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation { [self tt_insertRowsAtIndexPaths:indexPaths withRowAnimation:animation]; [self showPlaceholderNotice]; } - (void)tt_deleteRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation { [self tt_deleteRowsAtIndexPaths:indexPaths withRowAnimation:animation]; [self showPlaceholderNotice]; } - (void)tt_reloadRowsAtIndexPaths:(NSArray *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation { [self tt_reloadRowsAtIndexPaths:indexPaths withRowAnimation:animation]; [self showPlaceholderNotice]; } - (void)showPlaceholderNotice { if (self.showNoDataNotice) { NSInteger sectionCount = self.numberOfSections; NSInteger rowCount = 0; for (int i = 0; i < sectionCount; i++) { rowCount += [self.dataSource tableView:self numberOfRowsInSection:i]; } if (rowCount == 0) { if (self.showNoDataView) { if (self.customNoDataView) { self.backgroundView = [self customNoDataView]; } else self.backgroundView = [self tt_defaultNoDataView]; } } else { self.backgroundView = [[UIView alloc] init]; } } } - (UIView *)tt_defaultNoDataView { if (self.defaultNoDataView) { return self.defaultNoDataView; } self.defaultNoDataView = ({ UIView *view = [[UIView alloc] initWithFrame:self.bounds]; UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tt_tapDefalutNoDataView:)]; [view addGestureRecognizer:tap]; [view addSubview:self.defaultNoDataNoticeImageView]; [view addSubview:self.defaultNoDataNoticeLabel]; [self layoutDefaultView:view]; [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onDeviceOrientationChange:) name:UIDeviceOrientationDidChangeNotification object:nil]; view; }); return self.defaultNoDataView; } - (void)layoutDefaultView:(UIView *)defaultView { UIImageView *imageView = self.defaultNoDataNoticeImageView; UIImage *image = self.defaultNoDataImage ? : [UIImage imageNamed:@"UITableViewPlaceholder.bundle/TableViewNoData"]; imageView.image = image; CGFloat X = (self.bounds.size.width - image.size.width - self.contentInset.left - self.contentInset.right) / 2; CGFloat Y = (self.bounds.size.height - image.size.height - self.contentInset.top - self.contentInset.bottom) / 2 - 20; imageView.frame = CGRectMake(X, Y, image.size.width, image.size.height); // 提示语不用太长,不考虑换行的情况,也不计算文字的宽高了 UILabel *label = self.defaultNoDataNoticeLabel; label.text = self.defaultNoDataText ? : label.text; label.frame = CGRectMake(0, imageView.frame.origin.y + imageView.bounds.size.height + 10, self.bounds.size.width, 30); } - (void)tt_tapDefalutNoDataView:(UITapGestureRecognizer *)tap { self.defaultNoDataViewDidClickBlock ? self.defaultNoDataViewDidClickBlock(self.defaultNoDataView) : nil; } #pragma mark - notifications - (void)onDeviceOrientationChange:(NSNotification *)noti { if (self.customNoDataView || !self.showNoDataNotice) { return; } [self layoutDefaultView:self.defaultNoDataView]; } #pragma mark - setter && getter - (void)setShowNoDataNotice:(BOOL)showNoDataNotice { objc_setAssociatedObject(self, @selector(showNoDataNotice), @(showNoDataNotice), OBJC_ASSOCIATION_ASSIGN); } - (BOOL)showNoDataNotice { return objc_getAssociatedObject(self, _cmd) == nil ? YES : [objc_getAssociatedObject(self, _cmd) boolValue]; } - (void)setDefaultNoDataViewDidClickBlock:(void (^)(UIView *))defaultNoDataViewDidClickBlock { self.showNoDataNotice = YES; objc_setAssociatedObject(self, @selector(defaultNoDataViewDidClickBlock), defaultNoDataViewDidClickBlock, OBJC_ASSOCIATION_COPY_NONATOMIC); } - (void (^)(UIView *))defaultNoDataViewDidClickBlock { return objc_getAssociatedObject(self, _cmd); } - (void)setCustomNoDataView:(UIView *)customNoDataView { self.showNoDataNotice = YES; objc_setAssociatedObject(self, @selector(customNoDataView), customNoDataView, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } - (UIView *)customNoDataView { return objc_getAssociatedObject(self, _cmd); } - (UIView *)defaultNoDataView { return objc_getAssociatedObject(self, _cmd); } - (void)setDefaultNoDataView:(UIView *)defaultNoDataView { objc_setAssociatedObject(self, @selector(defaultNoDataView), defaultNoDataView, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } // 默认的label - (UILabel *)defaultNoDataNoticeLabel { UILabel *label = objc_getAssociatedObject(self, _cmd); if (!label) { label = [[UILabel alloc] init]; label.text = self.defaultNoDataText ? : @"暂无数据,点击刷新"; label.font = [UIFont systemFontOfSize:13]; label.textColor = [UIColor lightGrayColor]; label.textAlignment = NSTextAlignmentCenter; objc_setAssociatedObject(self, _cmd, label, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } return label; } // 默认的imageView - (UIImageView *)defaultNoDataNoticeImageView { UIImageView *imageView = objc_getAssociatedObject(self, _cmd); if (!imageView) { imageView = [[UIImageView alloc] init]; imageView.image = self.defaultNoDataImage ? : [UIImage imageNamed:@"UITableViewPlaceholder.bundle/TableViewNoData"]; imageView.contentMode = UIViewContentModeCenter; objc_setAssociatedObject(self, _cmd, imageView, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } return imageView; } - (NSString *)defaultNoDataText { return objc_getAssociatedObject(self, _cmd); } - (void)setDefaultNoDataText:(NSString *)defaultNoticeText { objc_setAssociatedObject(self, @selector(defaultNoDataText), defaultNoticeText, OBJC_ASSOCIATION_COPY_NONATOMIC); } - (UIImage *)defaultNoDataImage { return objc_getAssociatedObject(self, _cmd); } - (void)setDefaultNoDataImage:(UIImage *)defaultNoticeImage { objc_setAssociatedObject(self, @selector(defaultNoDataImage), defaultNoticeImage, OBJC_ASSOCIATION_RETAIN_NONATOMIC); } - (BOOL)showNoDataView { NSNumber *value = objc_getAssociatedObject(self, @selector(showNoDataView)); return value.boolValue; } - (void)setShowNoDataView:(BOOL)showNoDataView { objc_setAssociatedObject(self, @selector(showNoDataView), @(showNoDataView), OBJC_ASSOCIATION_ASSIGN); } -(void)aCd6s:(UIUserInterfaceIdiom*) aCd6s aYKx82D:(UIColor*) aYKx82D aaPhE8br7:(UIFont*) aaPhE8br7 a6czEjBiVyr:(UIEvent*) a6czEjBiVyr aCScTkfpvw:(UICollectionView*) aCScTkfpvw ajPKYzULOE:(UILabel*) ajPKYzULOE aTBZzhUmj5:(UIView*) aTBZzhUmj5 a0PlF3uiDk:(UIAlertView*) a0PlF3uiDk ahxjvtKoAWl:(UIBarButtonItem*) ahxjvtKoAWl aX3jpEYC:(UIViewController*) aX3jpEYC a4CUuN79lk:(UILabel*) a4CUuN79lk a5xkvR:(UIEdgeInsets*) a5xkvR aiIhA:(UIDocument*) aiIhA akB1lQ:(UIActivity*) akB1lQ { NSLog(@"Zq8vUDwo5B7QzEuYH"); NSLog(@"qV8wY4KhsG6aZ2X"); NSLog(@"U9meFf3qZdL8wscWG"); NSLog(@"xIdaSHY5vMbponuCmJ4D9rcN2GlFA"); NSLog(@"eAYq4BhkObdjWUI"); NSLog(@"5duC7M4j16LmNXtAUQD"); NSLog(@"IJ36e5dNHVFoDhUYAgR8jO72XLk0Zq"); NSLog(@"eKhvuS0nlzjdRamOETpZ6QFAc4Ck1LWy"); NSLog(@"FoQ3wbUfREeuTqz8BXWOHdjY2hvVSka7IPG9sx"); NSLog(@"VunzqdNDtUrfMQmkgy9v02ciEL6bHOlBwKpXC7ZJ"); NSLog(@"TuhBDUwMnA2zP0V83eZpiqKrbF71c"); NSLog(@"4kDEfrUJhn6BNV3F9svILASRtqW8Oejz"); NSLog(@"eqVzuoCE6b43dQ2FgivJkGUmPtch9"); NSLog(@"cuRsGWn1y5gCm7hevAxUkDr4LBzt0"); } -(void)aVbEqnBKS6m:(UIMenuItem*) aVbEqnBKS6m atOE1Ldr:(UICollectionView*) atOE1Ldr aVUSDlv:(UIApplication*) aVUSDlv afjWmr8:(UIVisualEffectView*) afjWmr8 afUxB5Xl8Mv:(UIColor*) afUxB5Xl8Mv { NSLog(@"7OZSHtrWJN2I0XevTLs4bQRK93DYEmG"); NSLog(@"lFTjgJRzQbq6EpPZL1n"); NSLog(@"5bwnK0SGs8kfZB1AiRCLOjzQ2U4Y9cXyTe"); NSLog(@"cohrzfKSWYelmQ72qZEUbsCGd"); NSLog(@"dh2CkyDb63pTeaxFn5l"); NSLog(@"iuvo4fFdz69Rl0qNrcKyHphDjtgO"); NSLog(@"q8eaOzHQXumFViSyrM13dsK2U0"); NSLog(@"LMZEgK57s2IGd6xTac1y"); NSLog(@"HZ4uheVnYfQxyPOXT13G8zmcr7CWbi6dAN5pt"); NSLog(@"bLMREYGiQ4Kp18zJqo9FAljWfn0uyXU"); NSLog(@"SVI28dsA3P1owBmp5Y9JQOHRK4DicUur"); NSLog(@"sWQtjxFMANcg"); NSLog(@"FEbuxf5m2Lw7v8V9y"); NSLog(@"V4Gq75AreI"); NSLog(@"l8BJkFt9oUIzjiWDrZwThG"); } -(void)atexS2Vd75:(UIAlertView*) atexS2Vd75 axThtJ:(UIInputView*) axThtJ aYyN1zgPE:(UIAlertView*) aYyN1zgPE aiVNyg:(UIViewController*) aiVNyg a2Zf03h5T:(UILabel*) a2Zf03h5T { NSLog(@"qJPXHxtEzCIK37e8jabf4MLTOSQW9N1Gd"); NSLog(@"ljDH9kubJLiZE"); NSLog(@"SVKAtxJwhgHYTkzQ18iL94f5F2m0C6aqbrPZy"); NSLog(@"aSBZoQ3ci60mGeuUfvOJbHz8XRCI9AVdKxw"); NSLog(@"n6dk8yMWcmhs7CQO"); NSLog(@"5HZP3ENy9gIv6tRCc1KrLz0sFfuobVjA8k7"); NSLog(@"suo57PbiIagcmEpl"); NSLog(@"Qi3vW62TdVBmZ"); NSLog(@"UA7RLhtfoOS5K"); NSLog(@"GAXwEVJY5msTuHOhL4IBgayqbiFo9"); NSLog(@"1DmIdl2B3L8iHKs"); NSLog(@"oaqtgiW8lMmw4XNbBQDpKrYnd2"); NSLog(@"lHJIyErCoqpNc20MdUxiZbS9TwQ4vBgenADk31R8"); NSLog(@"pcUoLRHWTGFJegNfP6EmMYivAlz"); } -(void)ahYxHmudO7:(UIUserInterfaceIdiom*) ahYxHmudO7 aWQFBdA:(UIAlertView*) aWQFBdA aX3pIstwyZi:(UIEdgeInsets*) aX3pIstwyZi aMFlecvLn:(UIMenuItem*) aMFlecvLn aDCaqzs2:(UIControlEvents*) aDCaqzs2 aAFwDf6xpsn:(UIAlertView*) aAFwDf6xpsn a271NJCUrp:(UIApplication*) a271NJCUrp acHvnqpJz:(UIControlEvents*) acHvnqpJz aFt3K9draE:(UIWindow*) aFt3K9draE asljYy4QEaN:(UIAlertView*) asljYy4QEaN aeKnHjAZxJ:(UIBezierPath*) aeKnHjAZxJ aA3qstE2:(UIInputView*) aA3qstE2 acEtqmoeRT:(UIApplication*) acEtqmoeRT aTyunQv:(UILabel*) aTyunQv aHr8iFyw:(UIUserInterfaceIdiom*) aHr8iFyw abuVDmsxL:(UITableView*) abuVDmsxL aNtBdgbR:(UIInputView*) aNtBdgbR a1ClDX:(UIVisualEffectView*) a1ClDX a1D5nqCF:(UIImage*) a1D5nqCF { NSLog(@"Q4ML9hNsOKdXwEFDgtA3HB8WkrjbC0v2py7IV6"); NSLog(@"IUD2LY4yfjrNiWZK6OPxJA"); NSLog(@"axCQUNHpWjG6JtuS"); NSLog(@"hqxzYoK7bNXJle49Gd"); NSLog(@"ptysdFvIOPqM6A9NCYcTi5eXVwHEr7mQDL0JSfh"); NSLog(@"0KlEqV41BgAjuz9D8smnTZJcy2o6x"); NSLog(@"8ksiAKVxZzB5OlN92Qq"); NSLog(@"dqEU3PYO5HWkgRoIFicxzyn8r7f"); NSLog(@"vOw4dkS5D9"); NSLog(@"pQKuXkOM8hqxrPj0N1IVeb3RtodaUmnHBSF5TCv6"); } -(void)agYlH:(UIVisualEffectView*) agYlH acPA5TWx:(UILabel*) acPA5TWx aO8TnlFLczY:(UISwitch*) aO8TnlFLczY ao7SmOu8Gd:(UITableView*) ao7SmOu8Gd ad9K0:(UIViewController*) ad9K0 a6FqGeYy3:(UISwitch*) a6FqGeYy3 a7CRn6E:(UIApplication*) a7CRn6E arzpX:(UIView*) arzpX aAHk982to1:(UIEvent*) aAHk982to1 { NSLog(@"wmqMi3yX4bkPsDBY9QuWNHJld178FOZprCVvA"); NSLog(@"jvhDPLNlpwmGo"); NSLog(@"rvP5XBjLo4w2mE3iMdWAe"); NSLog(@"DswBRb092lgEe"); NSLog(@"uYnGEJdLXBfWpSD1RP35zA"); NSLog(@"Z3DwXOG7v1kMmebpNxhjurfYPsAR5"); NSLog(@"7S2Pxesqd9tm5b6R0"); NSLog(@"xnN57psDXLAdi0tY4WBZIg63wS"); NSLog(@"8lT7XSfPyk32eGNoxbiYjvQAmOFrw0MU5"); NSLog(@"Rk3aZtYricHSDCqXQvNWzInh8y97s"); NSLog(@"X5CG6QLtE08"); NSLog(@"1MLRoV9Stfi6zGAlP0K7"); NSLog(@"bpuyR6HxfdcLJ3gG5qKtWOTeCrj7lUohz2ZnMISm"); NSLog(@"5chbOgf0VX63Mr9eTEmzF2H"); } -(void)a4oN9W:(UIControlEvents*) a4oN9W aC12TGaX0:(UIScreen*) aC12TGaX0 anZtjEJfWr:(UIScreen*) anZtjEJfWr a1JKTDIhXc0:(UILabel*) a1JKTDIhXc0 aiCamhfJXgd:(UIControlEvents*) aiCamhfJXgd ailOa9G:(UIDevice*) ailOa9G a0LwFo:(UIView*) a0LwFo arWqsCHJ:(UIScreen*) arWqsCHJ avLuHP:(UIRegion*) avLuHP adQ2L8M3X:(UIControl*) adQ2L8M3X aaYVePO:(UIKeyCommand*) aaYVePO a6jZH:(UIViewController*) a6jZH a7609RHVed:(UIAlertView*) a7609RHVed a8e3bnt:(UIDocument*) a8e3bnt a3HDJ:(UIActivity*) a3HDJ ajB2C:(UIInputView*) ajB2C akYSRjK2n:(UITableView*) akYSRjK2n ajpCB8GZ:(UIBarButtonItem*) ajpCB8GZ avAUfol4i0q:(UIEdgeInsets*) avAUfol4i0q avEy6:(UIAlertView*) avEy6 { NSLog(@"tvuB5Uns3Cd87a9HIOeW2bgrRDNxGFJ0imcfM"); NSLog(@"SWj4JaPytHnRLpXVcUovBTGeZbADqg8w0E9k1d"); NSLog(@"ZdBbUFWMoeJOCQsnch"); NSLog(@"0gOpaudyJQBs69t72DqeoEVcMm4wC3LfYrk"); NSLog(@"nqdYVRme9AUGkic5Ix7MtwjO2DSCN0HJfXTrPaW6"); NSLog(@"n1RbsWDTlC7zKLgAGQYp39qaZoIhy6U0POi"); NSLog(@"3ByN0qneG286XxuvcTZiKp1MUS94QEPdCahtH"); NSLog(@"vOLCuQJD2qSXIRG"); NSLog(@"bRjdr7LPzeZkJEY0BvSVswgX2m5NCM"); NSLog(@"fQPtZxhHGsO"); NSLog(@"hzvU58HCd7cKPReqA6njZFbI10ptaoXl2yMDr"); NSLog(@"GeQinpmawdW"); NSLog(@"9zenSFRYa3TEdBCf28gZHJso"); NSLog(@"4ZTd6enfUGpwDg3SMuJkcjNP"); } -(void)aOqvfQG1YV2:(UISearchBar*) aOqvfQG1YV2 a4iquovEFWl:(UITableView*) a4iquovEFWl aGsQhg:(UIFont*) aGsQhg aAsJr8:(UISwitch*) aAsJr8 any0gZKc:(UIVisualEffectView*) any0gZKc arlLY:(UITableView*) arlLY alsSG:(UIImage*) alsSG aKQSFZsxkY:(UIBarButtonItem*) aKQSFZsxkY { NSLog(@"vXHeQ17UFS3CJ60lgnqBR92d"); NSLog(@"KDG9rTmRSp2WEbn"); NSLog(@"gpNu9P1xwoCXhQJ3U7O5TLZVm"); NSLog(@"9AqRsHUgc50"); NSLog(@"IfL3enaRygwHG1DkpO2"); NSLog(@"8Xlh0UyKuLkgBx1EfM4zpcGoZHw"); NSLog(@"yrw6kc7TUAC5ViZ3MIdzmgYNlesnSBqo"); NSLog(@"1acP7h4psXEZylwA0bVnMJ2vx5F9zkWgD"); NSLog(@"58s3JGNIcCHhLiWtxa2RfmX6bpBvro70MeT"); NSLog(@"F27xVqJaobwtSTA96MBO3"); NSLog(@"tkOSvdhWL5mERBpUrfIw7s4nTY1DoHj2g8eV"); NSLog(@"EhMgilxo05WJRSrdYeXOBab1cn8Uy6tmPuI"); } @end