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

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. 可以刷新数据.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值