UI tableView 的头视图 & "小广告"

来源:互联网 发布:淘宝退款率计算 编辑:程序博客网 时间:2024/04/28 21:58
self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height - 64) style:UITableViewStylePlain];    [self.view addSubview:self.tableView];    [_tableView release];    self.tableView.dataSource = self;    self.tableView.delegate = self;    // 设置cell行高    self.tableView.rowHeight = 100;    self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, -200, self.view.frame.size.width, 200)];    self.imageView.image = [UIImage imageNamed:@"5.jpg"];    // 给tableview添加头视图(不动得一张图)     //  宽是tableView的宽度    self.tableView.tableHeaderView = self.imageView;

这样设置图片当你在下拉时,不会有任何改变.

可以试试以下代码的效果!

- (void)viewDidLoad {// 格外小广告    [self.tableView addSubview:self.imageView];    self.tableView.contentInset = UIEdgeInsetsMake(200, 0, 0, 0);}#pragma mark tableView 的delegate 已经签订好了scrollView的协议,只要设置好代理人,就可以使用scrollView的协议方法.- (void)scrollViewDidScroll:(UIScrollView *)scrollView{    CGFloat y = scrollView.contentOffset.y;    if (y < 0) {        self.imageView.frame = CGRectMake(0, y, self.view.frame.size.width, -y);    }    NSLog(@"%g",y);}

当然不要忘了写协议中的方法.

tableView有一个方法reloadData. 可以刷新数据.

0 0
原创粉丝点击