当前位置: 首页 > 知识库问答 >
问题:

iOS tableview的大小与tableViewWrapperView的大小不同

慎风畔
2023-03-14

以下是我遇到问题的tableViewController的代码

#import "BBTCampusInfoTableViewController.h"
#import "BBTCampusInfoManager.h"
#import "BBTCampusInfoTableViewCell.h"
#import <UIImageView+WebCache.h>

@interface BBTCampusInfoTableViewController ()

@end

@implementation BBTCampusInfoTableViewController

extern NSString * campusInfoNotificationName;

- (void)viewWillAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(didReceiveCampusInfoNotification) name:campusInfoNotificationName object:nil];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    self.automaticallyAdjustsScrollViewInsets = NO;
    //self.tableView.contentInset = UIEdgeInsetsZero;
    //Retrive all campus infos
    [[BBTCampusInfoManager sharedInfoManager] retriveData:@""];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return [[BBTCampusInfoManager sharedInfoManager].infoArray count];
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 140.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 0.5;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    UIView *view = [[UIView alloc] initWithFrame:CGRectZero];
    return view;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    NSString *cellIdentifier = @"infoCell";
    BBTCampusInfoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];

    if (!cell)
    {
        cell = [[BBTCampusInfoTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
    }

    NSArray *infoArray = [BBTCampusInfoManager sharedInfoManager].infoArray;

    [cell setCellContentDictionary:infoArray[indexPath.row]];

    [cell setNeedsUpdateConstraints];
    [cell updateConstraintsIfNeeded];

    return cell;
}

- (void)didReceiveCampusInfoNotification
{
    NSLog(@"Did receive campus info notification");
    [self.tableView reloadData];
}

共有3个答案

翁翰墨
2023-03-14

您是否尝试将此代码添加到viewDidload

self.edgesForExtendedLayout = UIRectEdgeNone;

或者尝试以下代码:

func tableView(tableView: UITableView, heightForHeaderInSection section: Int) -> CGFloat {
    return 0.5
}
func tableView(tableView: UITableView, viewForHeaderInSection section: Int) -> UIView? {

    return UIView(frame: CGRectZero)
}
郦祺
2023-03-14

如果使用interface builder,请尝试:

选择视图控制器,打开属性检查器,“调整滚动视图插入”默认为打开。

或以编程方式尝试:

self.automaticallyAdjustsScrollViewInsets=否;

在视图加载中

巫懿轩
2023-03-14

既然你一直说它不管用,试试这个,这有点难看,但它管用。(见图)

  • 只需在表视图之前添加一些UI组件-

如果表视图(或scrollview)是容器视图上的唯一/第一个子视图,则会发生这种情况。

作为一种解决方案,您可以取消勾选调整滚动视图插图

 类似资料:
  • 我花了好几天的时间让Spring Boot上传文件正常工作,但就像Spring一样,你不知道这个魔法是如何发挥作用的,即使多年来使用这个框架,你也必须通过谷歌搜索大量时间才能发现问题所在,并解决问题,就像你正在经历一个迷宫一样,这是一个可维护性的噩梦。 使用Spring Boot 2.2.0。M3进行文件上传,这两对设置有什么区别?哪个是正确的? 上面的“http”是否与Spring REST控制

  • 当我们用来谈论核心池大小和最大池大小之间的区别到底是什么? 可以借助示例来解释吗?

  • https://docs.oracle.com/javase/8/docs/api/java/util/Spliterator.html SIZED特征值表示在遍历或拆分之前从估计大小()返回的值表示有限大小,在没有结构源修改的情况下,表示完整遍历将遇到的元素数量的精确计数。 SUBSIZE Character 值表示 trySplit() 生成的所有拆分器都将同时具有 SIZE 和 SUBSIZ

  • 问题内容: 所以基本上我正在生成随机的10000个IP地址,我想存储在HashSet中找到的所有那些IP地址,但是根据我的计算,发现了大约6000个IP地址,但是在HashSet中仅存储了700个IP地址?HashSet在存储String方面是否有任何限制。任何建议将不胜感激。 问题答案: 就您而言,没有限制(限制是数组的最大大小,即2 ** 31)。 但是,仅存储 唯一 值,因此我的猜测是您仅生

  • 问题内容: 为什么会限制其大小? 我浏览了一些链接:http : //www.coderanch.com/t/540346/java/java/maximum-size-hold- String-buffer 。 是因为count成员变量是int吗? 假设我们有2 ^ 31-1个字符,并在其中追加了一些字符。Count成员变量将增加附加的字符数,如果Count变量已经达到最大值(2 ^ 31-1)

  • 我是Java的初学者,刚开始使用Intellij作为我的IDE。 当我使用它时,有时会延迟。 我更改了我的 xms 和 xmx 以获得更大的堆大小(xms = 1024,xmx = 2048),但它抛出了一个错误。 所以,我把它回滚了。 错误消息是这样的:“初始堆大小设置为大于最大堆大小的值”。 有什么问题? 如果可能,如何增加最大堆大小? 我用的是笔记本电脑,它有8GB内存。x64Intelli