Iphone UITableView头视图不断重复
我正在制作一个iPhone应用程序。在这个应用程序中,我有一个UITableView,它有一个UITableView标题。这就是我的代码的样子Iphone UITableView头视图不断重复,iphone,objective-c,ios,uitableview,Iphone,Objective C,Ios,Uitableview,我正在制作一个iPhone应用程序。在这个应用程序中,我有一个UITableView,它有一个UITableView标题。这就是我的代码的样子 UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 308, 50)]; view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sx_home_tablehead.p
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 308, 50)];
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sx_home_tablehead.png"]];
self.tableViewAppointments.tableHeaderView = view;
这就是我的iPhone上的样子
这就是我想要实现的
希望任何人都能帮助我
亲切的问候 如果要将其添加为表视图节标题,则需要按如下方式添加它
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(30, 0, 308, 50)];
view.backgroundColor = [UIColor colorWithPatternImage:[UIImage imageNamed:@"sx_home_tablehead.png"]];
//or,
UIImageView *view = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"sx_home_tablehead.png"]];
return view;
}
可以在中定义收割台的高度
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return height;
}
因为您明确指定了视图的框架。你不应该做这种可怕的黑客行为。请使用以下代码:
UIImageView *imgView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"header.png"]];
self.tableView.tableHeaderView = imgView;
通过实现委托方法将其添加为表视图节头这不会设置表头视图,而是设置节头。是的,确实如此。如果他想将其附加到表视图部分,这就是他正在寻找的。否则你的就对了。这对我很有用!但是我必须做些什么才能像上面的截图一样呢?@StefGeelen我怀疑如果你这样做,你会得到预期的结果(只要图像大小合适)。