Objective---C 给tableView添加头视图轮播图
2015-12-22 23:45
302 查看
// 设置属性
@property(nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)UIImageView *imageView;
@property(nonatomic,retain)NSMutableArray *arr;
// 初始化数组
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super
initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if (self) {
self.arr = [NSMutableArray
arrayWithObjects:@"宋江1",
@"卢俊义2",
@"吴用3",
@"公孙胜4",
@"关胜5",
@"林冲6",
@"秦明7" ,@"呼延灼8" ,
@"花容9",@"柴进10",
@"李应11",
@"朱仝12",@"鲁智深13",@"武松14",@"张三",@"李四",@"王五",@"田七",@"小刘",@"老谭",nil];
}
return
self;
}
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
self.tableView = [[UITableView
alloc] initWithFrame:self.view.frame
style:UITableViewStylePlain];
self.tableView.delegate =
self;
self.tableView.dataSource =
self;
[self.view
addSubview:_tableView];
[_tableView
release];
//
给tableView添加头视图轮播图
//
方式一
// 设置尺寸时,前三个数值没有影响
// self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 100)];
// self.imageView.image = [UIImage imageNamed:@"type.png"];
// self.tableView.tableHeaderView = self.imageView;
// [_imageView release];
//
方式二
self.imageView = [[UIImageView
alloc] initWithFrame:CGRectMake(0, -200,
self.tableView.frame.size.width, 200)];
self.imageView.image = [UIImage
imageNamed:@"type.png"];
//
平移图片
self.tableView.contentInset =
UIEdgeInsetsMake(200, 0, 0, 0);
[self.tableView
addSubview:_imageView];
[_imageView
release];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return
self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *reuse =
@"reuse";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:reuse];
if (!cell) {
cell = [[[UITableViewCell
alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:reuse] autorelease];
}
cell.textLabel.text =
self.arr[indexPath.row];
return cell;
}
@property(nonatomic,retain)UITableView *tableView;
@property(nonatomic,retain)UIImageView *imageView;
@property(nonatomic,retain)NSMutableArray *arr;
// 初始化数组
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil{
self = [super
initWithNibName:nibNameOrNil
bundle:nibBundleOrNil];
if (self) {
self.arr = [NSMutableArray
arrayWithObjects:@"宋江1",
@"卢俊义2",
@"吴用3",
@"公孙胜4",
@"关胜5",
@"林冲6",
@"秦明7" ,@"呼延灼8" ,
@"花容9",@"柴进10",
@"李应11",
@"朱仝12",@"鲁智深13",@"武松14",@"张三",@"李四",@"王五",@"田七",@"小刘",@"老谭",nil];
}
return
self;
}
- (void)viewDidLoad {
[super
viewDidLoad];
// Do any additional setup after loading the view.
self.tableView = [[UITableView
alloc] initWithFrame:self.view.frame
style:UITableViewStylePlain];
self.tableView.delegate =
self;
self.tableView.dataSource =
self;
[self.view
addSubview:_tableView];
[_tableView
release];
//
给tableView添加头视图轮播图
//
方式一
// 设置尺寸时,前三个数值没有影响
// self.imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 0, 100)];
// self.imageView.image = [UIImage imageNamed:@"type.png"];
// self.tableView.tableHeaderView = self.imageView;
// [_imageView release];
//
方式二
self.imageView = [[UIImageView
alloc] initWithFrame:CGRectMake(0, -200,
self.tableView.frame.size.width, 200)];
self.imageView.image = [UIImage
imageNamed:@"type.png"];
//
平移图片
self.tableView.contentInset =
UIEdgeInsetsMake(200, 0, 0, 0);
[self.tableView
addSubview:_imageView];
[_imageView
release];
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
return
self.arr.count;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
static NSString *reuse =
@"reuse";
UITableViewCell *cell = [tableView
dequeueReusableCellWithIdentifier:reuse];
if (!cell) {
cell = [[[UITableViewCell
alloc] initWithStyle:UITableViewCellStyleValue2
reuseIdentifier:reuse] autorelease];
}
cell.textLabel.text =
self.arr[indexPath.row];
return cell;
}
相关文章推荐
- Objective-C中的属性和实例变量
- Effective Objective-C 2.0 学习笔记---(一)
- pip安装模块警告InsecurePlatformWarning: A true SSLContext object is not available.
- 高效开发iOS系列(runtime篇) -- 巧妙运用对象关联(Associated Objects)来设计alertview
- A Practicable Method for Ferromagnetic Object Moving Direction Identification
- Object类的常见方法
- 【Objective-C学习记录】第二十一天
- Objective-C——判断对象等同性
- objective-C_语言_委托模式
- Objective-C_语言_单例模式
- Objective-C代码混淆
- #Objective - C - sixth-Day 数组排序及集合遍历
- Objective-C:Foundation框架-结构体
- Objective--C UI UITableView编辑
- GridView绑定后翻页问题解决(PageIndexChanging(object sender, GridViewPageEventArgs e))
- Objective-C中的Method Swizzling
- js打印object信息
- SQL Server OBJECT_ID() 函数
- 自己做得json测试类,包含JSONArray,JSONObject,Gson基本使用方法
- Objective-C:Foundation框架-概述