[英]Remove extra cells/rows whitespace without data appearing on UITableView
[英]How to remove extra whitespace above a UITableView?
我一直在尝试使表的标题与UITableView
一起滚动。 它终于可以工作了,但是,现在地图视图正下方显示了一个空白 (请参见屏幕截图)。 我很难在表标题部分中获取地图以与表一起滚动,也难以通过用户触摸使UIButton在表标题内触发(UIButton只是将地图扩展为全屏)。
昨天我问了一个与此有关的问题,涉及滚动和按钮触摸。 这些现在正在工作-我确定编码可以做得更好,但这是我目前所拥有的,必须尽快完成。 如果可以解决此空白问题,则可以在以后重构和优化代码。
感谢您对此的任何帮助。
注意屏幕截图中表格下方和表格视图上方的空白-我想将表格视图带到地图附近。
在我的viewDidLoad
:方法中
// mapview
self.topMapView = [[MKMapView alloc] initWithFrame:CGRectMake(0, 0, 320, 140)];
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0,0,self.view.frame.size.height,self.view.frame.size.height)];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.backgroundColor = [UIColor whiteColor];
[self.view addSubview:self.tableView];
然后在viewForHeaderInSection:
方法中(建议在viewDidLoad:
方法中完成此操作,我尝试过这样做,但这给了我更多的问题
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 140)];
UIButton *showMapButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
showMapButton.frame = CGRectMake(0.0, 0, 320.0, 140.0);
[showMapButton setTitle:@"show map" forState:UIControlStateNormal];
[showMapButton addTarget:self
action:@selector(mapDetailViewDisplay:)
forControlEvents:UIControlEventTouchDown];
[headerView addSubview:self.topMapView];
[headerView showMapButton];
self.tableView.tableHeaderView = headerView;
return headerView;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 140;
}
只需在您的ViewDidLoad方法中添加它
self.automaticallyAdjustsScrollViewInsets = NO;
[UITableView tableHeaderView]
与viewForHeaderInSection
不同,但是您要为两个对象都设置相同的对象。
您应该在viewDidLoad:
设置self.tableView.tableHeaderView
,或者根据要尝试实现的行为通过viewForHeaderInSection委托方法返回headerView。
尝试将所有代码移到- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
,仅return headerView
在viewDidLoad
并改变
UIView *headerView = [[UIView alloc] init];
代替
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0,0, 320, 140)];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.