iOS11.0 适配 tableView上面空出一段空白

大家好,最近一直忙于工作,忙于生活,没有时间写博客。好吧,这都是借口

今天主要编写的是笔者在实际开发中遇到的问题,首先笔者先阐述一下出现此问题的环境。

1、编写了一个用户引导页的功能

2、用OC的masonry进行tableView的布局

出现的场景:第一次打开app时候 就会出现tableView上面会有一段的空白。当第二次打开的时,就显示正常了

具体的代码:

    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, 0, 0) style:UITableViewStylePlain];
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIApplicationBackgroundFetchIntervalNever;
    } else {
        self.automaticallyAdjustsScrollViewInsets = false;
    }
    
    self.tableView.backgroundColor = [UIColor whiteColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"LoansTableViewCell" bundle:nil] forCellReuseIdentifier:@"LoansTableViewCell"];
    self.tableView.tableHeaderView = [self creatTableViewHeaderView];
    self.tableView.tableFooterView = [self creatTableViewFooterView];
    [self.tableView addSubview:[self creatBGViewHeaderView]];
    [self.view addSubview:self.tableView];
    
    BlockWeakSelf weakSelf = self;
    [self.tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(weakSelf.view.mas_top).offset(MARVIEWH);
        make.left.mas_equalTo(weakSelf.view.mas_left).offset(0);
        make.right.mas_equalTo(weakSelf.view.mas_right).offset(0);
        make.bottom.mas_equalTo(weakSelf.view.mas_bottom).offset(-TABBAR_HEIGHT);
    }];
错误的界面样式:


以上都是出现问题的环境和具体的步骤。通过笔者不断的尝试,终于解决了,


解决方案:

1、代码设置tabelView的frame和用masonry设置的要一致,不然就会出现上述所说那种情况


解决之后的代码:



注意 两个红色框的frame其实是一致的


下面是笔者的联系方式:

qq   3145419760

微信号   WSMl062925

邮箱   wusong_gongzuo@163.com





  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,以下是一个简单的iOS Tableview代码示例: 首先,在你的ViewController.h文件中添加UITableViewDelegate和UITableViewDataSource协议: ``` @interface ViewController : UIViewController<UITableViewDelegate, UITableViewDataSource> ``` 然后,在你的ViewController.m文件中,初始化一个UITableView,并实现UITableViewDataSource和UITableViewDelegate协议的方法: ``` - (void)viewDidLoad { [super viewDidLoad]; UITableView *tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStylePlain]; tableView.delegate = self; tableView.dataSource = self; [self.view addSubview:tableView]; } - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { return 10; // 返回10行 } - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { static NSString *cellIdentifier = @"CellIdentifier"; UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier]; if (cell == nil) { cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier]; } cell.textLabel.text = [NSString stringWithFormat:@"Row %ld", (long)indexPath.row]; return cell; } - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [tableView deselectRowAtIndexPath:indexPath animated:YES]; NSLog(@"Selected row %ld", (long)indexPath.row); } ``` 这个示例会在你的ViewController上创建一个UITableView,其中包含10行简单的文本。当你点击任何一行时,它会在控制台上打印所选行的索引。 希望这可以帮助你开始实现你自己的表视图!
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值