我有一个简单的UITable,我希望在桌子开始之前有一个小图像,所以我到目前为止使用了一个表头很好,这很好用
self.table.tableHeaderView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:img]];
只有奇怪的是当我尝试滚动表格视图行时表格滚动但当我尝试滚动标题没有任何反应时,它就像滚动侦听器没有听到标题上的滚动事件。
为了清楚,当您将表格作为一个整体滚动时,标题会滚动(这是所需的行为)
我像疯了一样google,但似乎找不到答案,谢谢!
一些额外的代码
- (void)viewDidLoad
{
[super viewDidLoad];
// set the table header
self.table.tableHeaderView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header"]];
// add empty footer view to hide empty cells
self.table.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
// set title
self.navigationItem.title = [self.catData objectForKey:@"titlePage"] ? [self.catData objectForKey:@"titlePage"] : [self.catData objectForKey:@"title"];
}
答案 0 :(得分:1)
使用分组表视图。然后你可以滚动你的表格视图。
答案 1 :(得分:0)
您是否尝试过设置标题视图:
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
return [[UIImageView alloc] initWithImage:[UIImage imageNamed:img]];
}
答案 2 :(得分:0)
您需要实现以下方法: -
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
CGRect rect = self.tableView.tableHeaderView.frame;
rect.origin.y = MIN(0, self.tableView.contentOffset.y);
self.tableView.tableHeaderView.frame = rect;
}