美文网首页
tableView 小技巧

tableView 小技巧

作者: 致在路上的我们 | 来源:发表于2018-01-17 11:29 被阅读0次

    1.tableview section头部不悬停
    正常section不为0的时候,sectionheaderView会悬停在当前视图中,如QQ
    解决办法

    #pragma mark -- 头部悬停
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        CGFloat sectionHeaderHeight = kViewHeightScaleOf6s(97);
        if (scrollView.contentOffset.y <= sectionHeaderHeight && scrollView.contentOffset.y >= 0) {
            scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
        } else if (scrollView.contentOffset.y >= sectionHeaderHeight) {
            scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
        }
    }
    
    

    2.tableView系统选中方法

    self.tableview.allowsMultipleSelectionDuringEditing = YES;
    self.tableview.editing = YES;
    

    3.mj上拉加载重复加载问题

    UIScrollView (MJRefresh)
    
    - (void)setMj_footer:(MJRefreshFooter *)mj_footer
    {
        if (mj_footer != self.mj_footer) {
            // 删除旧的,添加新的
            [self.mj_footer removeFromSuperview];
            [self insertSubview:mj_footer atIndex:0];
       // ios11 适配 关闭self-sizing
            if ([self isKindOfClass:[UITableView class]]) {
                UITableView *view = (UITableView *)self;
                view.estimatedRowHeight = 0;
                view.estimatedSectionHeaderHeight = 0;
                view.estimatedSectionFooterHeight = 0;
            }
            // 存储新的 
        [self willChangeValueForKey:@"mj_footer"]; // KVO
            objc_setAssociatedObject(self, &MJRefreshFooterKey,
                                     mj_footer, OBJC_ASSOCIATION_ASSIGN);
            [self didChangeValueForKey:@"mj_footer"]; // KVO
        }
    }
    

    4.ios11 用到tableview headerview 的时候需要用到下面的预估代码, 不用的话会出错

    if (@available(iOS 11.0,*)) {
            [UIScrollView appearance].contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
            
            //解决iOS11,仅实现heightForHeaderInSection,没有实现viewForHeaderInSection方法时,section间距大的问题
            [UITableView appearance].estimatedRowHeight = 0;
            [UITableView appearance].estimatedSectionHeaderHeight = 0;
            [UITableView appearance].estimatedSectionFooterHeight = 0;
    }else{
            self.automaticallyAdjustsScrollViewInsets = NO;
        }
    

    5.iphone_X适配:

    // 判断是否是iPhone X
    #define iPhoneX ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) : NO)
    // 导航栏高度
    #define KNAVIGATION_BAR_HEIGHT (iPhoneX ? 88.f : 64.f)
    // 状态栏高度
    #define KSTATUS_BAR_HEIGHT (iPhoneX ? 44.f : 20.f)
    // tabBar高度
    #define KTAB_BAR_HEIGHT (iPhoneX ? (83.f) : 49.f)
    // 底部的高度
    #define KBOTTOM_HEIGHT (iPhoneX ? 34.f : 0.f)
    

    相关文章

      网友评论

          本文标题:tableView 小技巧

          本文链接:https://www.haomeiwen.com/subject/zmwyoxtx.html