[英]UITableView in UITableViewCell won't scroll to bottom
我有一个UITableViewCell
用UITableView
中使用自定义单元格与77的高度,我不能滚动一路虽然UITableView中,最后一排被切断。
我正在使用此代码为表格视图创建框架。
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
_routeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, screenWidth, screenHeight) style:UITableViewStylePlain];
这是一个简短的视频,显示我的问题:
有人对我如何正确浏览路线有任何建议吗?
似乎没有空间可以向上移动单元格,而不仅仅是切断最后一个单元格。
-(void)configureRouteTableView
{
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
_routeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, screenWidth, screenHeight - 50) style:UITableViewStylePlain];
_routeTableView.delegate = self;
_routeTableView.dataSource = self;
_routeTableView.hidden = YES;
_routeTableView.separatorColor = [UIColor clearColor];
[_routeTableView setBackgroundColor:[UIColor clearColor]];
[self.contentView addSubview:_routeTableView];
}
我的个人经历
1)确保滚动内容的大小是uitableview单元格大小的倍数
2)确保桌面视图的y坐标加上桌面视图的高度不超过屏幕。
对于您的情况,我认为是第二个原因给您造成了麻烦。 以来,
_routeTableView = [[UITableView分配] initWithFrame:CGRectMake(0,50,screenWidth,screenHeight)style:UITableViewStylePlain];
50 + screenHeight,表示表格视图的某些部分不在屏幕上。 :)
多亏了建议者的建议。 我不确定为什么我无法利用您的编辑。
如我所见,您有两种方法可以解决此问题:
1)首先调整UITableView的框架:
_routeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, self.navigationController.navigationBar.frame.size.height, screenWidth, screenHeight - self.navigationController.navigationBar.frame.size.height) style:UITableViewStylePlain];
这意味着表格视图的高度是屏幕的高度减去导航栏的高度,并且从y轴的导航栏开始。
2)给UITableView的页脚添加一些高度。 (不建议)
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section { return 50.0f; }
另外,请确保此委托函数返回实际像元高度:
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return yourTableCellHeight;
}
我需要将框线更改为:
_routeTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 50, screenWidth, 90) style:UITableViewStylePlain];
请按以下方法设置表格单元格高度。
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return height;//77
}
尝试使用tableview的contentInsets。 您可以在IB中进行设置。 但是先禁用自动布局。
我使用自动布局约束来解决此问题,而不是让iOS做(错误)事情:
如果您使用Podfile,请安装UIView + Autolayout :
pod 'UIView+Autolayout'
包括UIView-Autolayout.h
#import "UIView-Autolayout.h"
并在您的viewDidLoad中使用它:
[tableView setTranslatesAutoresizingMaskIntoConstraints:NO];
[tableView pinToSuperviewEdges:JRTViewPinAllEdges inset:0.0];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.