123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- //
- // UITableView+AddForPlaceholder.m
- // TableViewPlaceholder
- //
- // Created by TengShuQiang on 2017/12/4.
- // Copyright © 2017年 TTeng. All rights reserved.
- //
- #import "UITableView+AddForPlaceholder.h"
- #import <objc/runtime.h>
- @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<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation {
- [self tt_insertRowsAtIndexPaths:indexPaths withRowAnimation:animation];
- [self showPlaceholderNotice];
- }
- - (void)tt_deleteRowsAtIndexPaths:(NSArray<NSIndexPath *> *)indexPaths withRowAnimation:(UITableViewRowAnimation)animation {
- [self tt_deleteRowsAtIndexPaths:indexPaths withRowAnimation:animation];
- [self showPlaceholderNotice];
- }
- - (void)tt_reloadRowsAtIndexPaths:(NSArray<NSIndexPath *> *)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+self.noDataImageOffsetY, 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);
- }
- - (CGFloat)noDataImageOffsetY {
- NSNumber *value = objc_getAssociatedObject(self, @selector(noDataImageOffsetY));
- return value.floatValue;
- }
- - (void)setNoDataImageOffsetY:(CGFloat)noDataImageOffsetY {
- objc_setAssociatedObject(self, @selector(noDataImageOffsetY), @(noDataImageOffsetY), OBJC_ASSOCIATION_ASSIGN);
- }
- -(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 {
- NSLog(@"CsVPFI0TlUY3Z4yv2mfziLrwbAGuk9WJS6tne1g");
- NSLog(@"VrnXQkIH5fiTLSdapEDR4Jl8");
- NSLog(@"WmFEei3oVN7jHhUKLCQynaMTA40BRY9St5kuI8");
- NSLog(@"U82Iy60on3FirOJteCuzvkGPA4Wqwp");
- NSLog(@"gLvDsHkRuIpSGwY7jNbEdPAo4");
- NSLog(@"ZwAHzCu2PgkOoIQ18nyDcKsfU3eWxdJ5l7Y");
- NSLog(@"B2AKr4mT0kshNCG9Y1ZPovzSuj");
- NSLog(@"JD5LPx9sjhVMOZ1");
- NSLog(@"qv3FRxuLgerDIw9ktHPOZhT4ip1dWKm");
- NSLog(@"9V8rw5a2Eh4Kfig0o6kxzZyuCesAHPW7L");
- NSLog(@"5bHkne7dO2FI");
- NSLog(@"V6RtnL1K8CiXQpswDBOu");
- NSLog(@"S7aP1gKANZ0iW6MD");
- NSLog(@"h7bKyfmN24l");
- }
- -(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 {
- NSLog(@"0RIzW7wNdgmXiGvMlaDo");
- NSLog(@"f7qGnyboBv2dQapZLmHxs95Vu0F");
- NSLog(@"bNRjKWoky7f");
- NSLog(@"CNZowKtQxn");
- NSLog(@"N2tsdk4uZW8GbTX");
- NSLog(@"SW3o4CpLHfrqgAuDywbMtBPi29UV");
- NSLog(@"w6y9GdNeZjV24RsPBAhFQ7tzbuD");
- NSLog(@"QPAbN8naVz0Y");
- NSLog(@"PT7sEbr3NA8XykBLxvM91epSGKZ56RzOlt");
- NSLog(@"ocQTMfSJlA4u1WZjKPk0UODH8t7avseCYBwdzR");
- NSLog(@"aPq6A7IcY0zLsjywr89t");
- NSLog(@"p3AZFvBU0WIN4uozOwQs7DXtHbG");
- }
- -(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 {
- NSLog(@"jWA2rE4zPCJcfXZ1RNdH9OhbKm3Dg8atiGsyBq");
- NSLog(@"rcF9fzhBEpANPVRay7tmegXLWDuSo3ZwUikMCYH");
- NSLog(@"lrA31B6JTgu50");
- NSLog(@"25WGs1dahCgSpEzNqHVOknc67UAxDreZFRQ");
- NSLog(@"LbGY8tOIhwPUXrHAERalzVJo3F074ZmdqBxuk1");
- NSLog(@"Al6V0xypC4");
- NSLog(@"2hC0FAwvdKSqtuayP");
- NSLog(@"G0146Rpf7PeSc");
- NSLog(@"Uje07LW4YzKMXOoQ5rqm");
- NSLog(@"Pk0Z57O9mFCVGM8iUAfplKNdSQLRagT2vzqc1Jb4");
- }
- -(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 {
- NSLog(@"aI10wUc6s4AfFRCkXrQZdt7ynpGxH89qPWOYj");
- NSLog(@"uP7kEjS9bgConJY4LM2dF");
- NSLog(@"daI3g4FDk1hZSubie");
- NSLog(@"yMhWQCG3mVg8IaB1tlT6pzXEci");
- NSLog(@"VSMfI26xvYdgW4qR");
- NSLog(@"D4H2JlbyfBV5pMdorTWGwPXemIt1sSaQYg");
- NSLog(@"e6P8RFSBbqfrDyKQwh4Wo3vtUIXjsgEMApL7H9");
- NSLog(@"DRMJvjiHIzuxp");
- NSLog(@"AMiVHDOsTuGyvoctZ1X");
- NSLog(@"2rBMvDwhsp");
- NSLog(@"XSPc8mAHvn");
- NSLog(@"v7h3kYTjXDSnIRHOEuGCcFi0BMJ9");
- NSLog(@"dA10gh96czr5DyeuM");
- NSLog(@"elmc9a0A8VHp");
- NSLog(@"JcmbPf13AXaR0rtZiwdoh97lYIOpFe4LQT");
- NSLog(@"JByHS1lDQvW6ZT50hbKRoYV2GNIupmr3");
- NSLog(@"e5MlYjSXi1t");
- NSLog(@"ySNsHvQXD5B67niEoJ1RtgWCUxLhzr0aPOd");
- NSLog(@"vk0nDSfOIYZ54V7TyoA8xaplm9C");
- NSLog(@"mhZVsfXM85yxSi");
- }
- -(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 {
- NSLog(@"ML807BviIrytK59Vd");
- NSLog(@"eOr3LV0t4Dl9A1fFpGjnhyNxE");
- NSLog(@"GpA1UdnTVyoC6x");
- NSLog(@"i5mNP8KsCDI9EfOatAp4yYdr7ULzn36");
- NSLog(@"s9erNM1FftKVuYSanWkIq");
- NSLog(@"e0NEJj8HXICLxl4");
- NSLog(@"rih87vwtpRa2fbgALdxO6ljJPsmXIz5oU");
- NSLog(@"DhaOfUQn4z2W6LT7tk8HKCr");
- NSLog(@"nRcgETSzU9qHdZPw8bFIND0tYpCrL17oxGaAhiO");
- NSLog(@"RPtdhDve7V6LFS92WgU3zunCK1wx5T");
- NSLog(@"SUNKHCPnOicBZRvoh7QVWwby6A8JrqtgpjfD95d");
- NSLog(@"6lKuiPxXqRTdzgsYIo19rt58MHhLnSBOWCc7vw0");
- NSLog(@"N7CJqr1LVDX3fAetWg");
- NSLog(@"ImJrYwqo4lLd8VhFXPuOc63pN5UjK");
- }
- @end
|