ios 处于UIScrollview上的UITableView添加了tabheaderview后,最下方的cell无法滚动到

新手上路,请多包涵

问题描述

我在做一个APP设置界面,最上方是一个UIView,下面紧跟着是一组Tableview.我想让UIView跟着UITableView滚动,所以把UIView当做UITableView的头视图添加了进去.添加成功后,TableView最底下一个cell滚动不下去,显示不完全,没有添加UIVide的时候一切正常

问题出现的环境背景及自己尝试过哪些方法

自己尝试改变过UIScrollView的内容视图大小,发现并不管用.

相关代码

// 请把代码文本粘贴到下方(请勿用图片代替代码)

-(void)loadUserInterFaceView{
_userInter = [[UIView alloc]initWithFrame:CGRectMake(0, 0, VCSelfWidth, 100)];
_userInter.backgroundColor = [UIColor whiteColor];
[_scrollview addSubview:_userInter];
_tableView.tableHeaderView = _userInter;
UITapGestureRecognizer *tapGesturRecognizer=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
[_userInter addGestureRecognizer:tapGesturRecognizer];
} //_userInter是头部视图,高度为100;


-(void)initTableview{
_tableView=[[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
_tableView.backgroundColor=axbackgrond;
_tableView.frame=CGRectMake(0,0,VCSelfWidth,VCSelfHeight);
_tableView.dataSource=self;
_tableView.delegate=self;
_tableView.scrollEnabled =YES;
[self loadUserInterFaceView];
[_tableView addSubview:_userInter];
_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
_items = [NSArray arrayWithObjects:@"出差",@"通知",@"旅程",@"邀请好友",@"礼金券",@"开展体验",@"设置",@"获取帮助",@"向我们反馈", nil];

}
-(void)loadScrollerView{

_scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 64, VCSelfWidth, VCSelfHeight-64)];//64是自定义的UINavgitaionController导航栏高度
_scrollview.backgroundColor = [UIColor whiteColor];
_scrollview.bounces = YES;
_scrollview.scrollsToTop = YES;
_scrollview.contentSize = CGSizeMake(VCSelfWidth,100+70*9);
_scrollview.scrollEnabled =  YES;
_scrollview.showsVerticalScrollIndicator = NO;
[self.view addSubview:_scrollview];
[self initTableview];
[_scrollview addSubview:_tableView];

}

  • (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
    }
  • (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return _items.count;
    }
  • (CGFloat)tableView:(UITableView )tableView heightForRowAtIndexPath:(NSIndexPath )indexPath{
    return 70;
    }

你期待的结果是什么?实际看到的错误信息又是什么?

我把UIScroller的contentSize值高度增加了100,也就是UIView的高度,为什么滚动到底部显示在倒数第二个cell的中间.最后一个cell无法显示

阅读 3.2k
1 个回答

虽然回答晚了,还是指出问题:
你将headerView错误的添加到了scrollView中,这行代码应删掉:

[_scrollview addSubview:_userInter];
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进