点击tableview的头视图按钮来达到收放tableview的列表
来源:互联网 发布:全新英朗刷启停软件 编辑:程序博客网 时间:2024/03/29 00:15
//
// ViewController.m
// XIBForiPad
//
// Created by Lu_Ca on 15/8/12.
// Copyright (c) 2015年 Lu_Ca. All rights reserved.
//
//
//点击tableview的头视图按钮来达到收放tableview的列表
//
#import "ViewController.h"
#import "XibForCell.h"
#import "XibModel.h"
@interface ViewController ()<UITableViewDataSource,UITableViewDelegate>
@end
@implementation ViewController
{
UITableView *_tabelView;
NSMutableArray *_dataSource;
UIButton *button;
XibModel *_modle;
}
- (void)viewDidLoad {
[superviewDidLoad];
_dataSource = [NSMutableArrayarray];
_modle = [[XibModelalloc] init];
_modle.isOn =YES;
_tabelView = [[UITableViewalloc] initWithFrame:CGRectMake(0,0, 1024,768) style:UITableViewStyleGrouped];
_tabelView.delegate =self;
_tabelView.dataSource =self;
[self.viewaddSubview:_tabelView];
for(NSInteger i =0 ;i<15;i++){
XibModel *model = [[XibModelalloc] init];
model.name = [NSStringstringWithFormat:@"小明%d",i];
model.age = [NSStringstringWithFormat:@"%d",10+i];
model.sex =@"男";
[_dataSourceaddObject:model];
}
// Do any additional setup after loading the view, typically from a nib.
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
return 80;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
button = [UIButtonbuttonWithType:UIButtonTypeCustom];
button.frame =CGRectMake(0,0, 1024, 80);
[buttonaddTarget:selfaction:@selector(clickHeaderButton:)forControlEvents:UIControlEventTouchUpInside];
button.backgroundColor = [UIColorredColor];
return button;
}
//点击头视图按钮,是列表达到收放
- (void)clickHeaderButton:(UIButton *)sender
{
//sender.selected = !sender.selected;用这种方式来区分判断是不行的,因为每次刷新就会调用tableview的头视图,就会重新创建头视图的按钮。达不到效果,所以需要有一个页面加载后只创建一次的变量来记录
_modle.isOn = !_modle.isOn;
[_tabelViewreloadSections:[NSIndexSetindexSetWithIndex:0]withRowAnimation:UITableViewRowAnimationAutomatic];
NSIndexPath *indexPath = [NSIndexPathindexPathForItem:0inSection:0];
if(_modle.isOn){//选中
[_tabelViewscrollToRowAtIndexPath:indexPath atScrollPosition:UITableViewScrollPositionMiddleanimated:YES];
}
}
//不同的情况不同的行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
if(_modle.isOn){
return _dataSource.count;
}
return 0;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
return 122;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
NSString *cellid = @"xib";
XibForCell *cell = [tableView dequeueReusableCellWithIdentifier:cellid];
if(!cell){
cell = [[[NSBundlemainBundle] loadNibNamed:@"XibForPad"owner:selfoptions:nil]lastObject];
}
XibModel *model = _dataSource[indexPath.row];
cell.name.text = model.name;
cell.age.text = model.age;
cell.sex.text = model.sex;
return cell;
}
- (void)didReceiveMemoryWarning {
[superdidReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
@end
- 点击tableview的头视图按钮来达到收放tableview的列表
- tableView 头视图的高度
- UI tableView 的头视图 & "小广告"
- iOS tableView 改变头视图和脚视图的颜色
- TableView头视图
- 点击tableView的cell弹出tableView
- 封装的轮播图作为头视图的tableview
- 关于iOS 11 tableView跟导航栏之间有空白和tableview的头视图问题
- 点击scrollview里面的按钮更换tableview的内容(tableview内容来自sqlite3) iOS
- 一个tableView的Cell中有两个点击按钮及tableView的重用
- 背景视图上点击事件与tableView冲突的解决办法
- tableView中添加按钮触发不了点击事件的解决办法
- iOS 不同按钮点击显示不同的tableview数据
- 解决tableview上按钮点击效果的延迟现象
- tableView视图列表3: 把解析到的XML数据显示在TableView上
- 关于tableView点击状态栏列表回到顶部的说明
- tableview实现qq好友列表点击拉伸的效果
- 关于tableView点击状态栏列表回到顶部的说明
- MySQL索引类型
- Agri-Net POJ 1258 【Prim】
- CSUOJ:集训队组队计划
- Elastos测试框架搭建--测试用例运行流程
- Shell脚本学习(一) - 创建脚本
- 点击tableview的头视图按钮来达到收放tableview的列表
- 关于BaseAdapter的getView方法的理解
- HDU 5378 Leader in Tree Land 树形背包
- 知乎向左,果壳向右
- roll pitch yaw
- Android------使用C/C++调用SO库
- spring aop(一)
- Longest Common Pefix
- 负载均衡学习笔记