//
// ViewController.m
// tableview
//
// Created by chenvinci on 2017/2/12.
// Copyright © 2017年 cuijing. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()<UITableViewDataSource>
@property(nonatomic,strong) UITableView* myView;
@property(nonatomic,strong) UIView* headerView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self myView];
self.myView.rowHeight = 60;
self.headerView = [[UIView alloc]init];
//headerView
UIImageView*img = [[UIImageView alloc]init];
img.image = [UIImage imageNamed:@"k.jpg"];
self.headerView.frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height/self.view.frame.size.width*img.image.size.width);
img.frame = self.headerView.frame;
[self.headerView addSubview:img];
self.myView.tableHeaderView = self.headerView;
}
-(UITableView*) myView{
if (!_myView) {
_myView = [[UITableView alloc]initWithFrame:self.view.frame style:UITableViewStylePlain];
[self.view addSubview:_myView];
_myView.dataSource = self;
}
return _myView;
}
//有多少节
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
return 1;
}
//每节几行
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return 3;
}
//tableviewcell
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
//indextPath.section 节
//indexPath.row 行
static NSString*identifier = @"cell";
//重用cell
UITableViewCell* cell = [tableView dequeueReusableCellWithIdentifier:identifier];
if (cell == nil) {
cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
}else{
NSLog(@"cell重用");
}
cell.textLabel.text = @"汪峰";
cell.detailTextLabel.text = @"春天里";
cell.imageView.image = [UIImage imageNamed:@"0.jpg"];
cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;//->
return cell;
}
//tableview的 style :grouped
-(NSString *)tableView:(UITableView *)tableView titleForFooterInSection:(NSInteger)section{
if (section == 0) {
return @"kkk end";
}else{
return @"kkk2 end";
}
}
-(NSString*)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section{
if (section == 0) {
return @"kkk ";
}else{
return @"kkk2 ";
}
}
@end
网友评论