UITableView底部有一个空白区域

时间:2015-02-05 08:46:24

标签: ios uitableview

我想在viewController的视图中创建一个UITableView,但不是在空洞屏幕上创建。

    _myTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WINDOW_WIDTH, 400) style:UITableViewStylePlain];
    _myTableView.dataSource = self;
    _myTableView.delegate = self;
    [_myTableView registerNib:[UINib nibWithNibName:@"MyKuCunTableViewCell" bundle:nil] forCellReuseIdentifier:kMyKuCunCell];
    [self.view addSubview:_myTableView];

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:    (NSInteger)section
{
    return 10;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
MyKuCunTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:kMyKuCunCell];
if (!cell) {
    NSArray *nib=[[NSBundle mainBundle] loadNibNamed:@"MyKuCunTableViewCell" owner:self options:nil];
    cell = [nib lastObject];
   }
    return cell;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 44.0f;
}

但是出了点问题:滚动到顶部时有一个空白!请注意指标。

怎么回事?当UITableView充满了屏幕时,我在过去看不到这一点。 (红色是空白区域)

我找到了解决方案,看到了2号回答。谢谢大家!

enter image description here

2 个答案:

答案 0 :(得分:0)

您可以尝试将这两个属性设置为0

@property (nonatomic)          CGFloat                     sectionHeaderHeight;   // will return the default value if unset

@property (nonatomic)          CGFloat                     sectionFooterHeight;   // will return the default value if unset

这两个为零

@property (nonatomic, retain) UIView *tableHeaderView;                           // accessory view for above row content. default is nil. not to be confused with section header

@property (nonatomic, retain) UIView *tableFooterView;                           // accessory view below content. default is nil. not to be confused with section footer

答案 1 :(得分:0)

我找到了解决方案:

    self.automaticallyAdjustsScrollViewInsets = NO;

希望它有所帮助!

相关问题