iOS tableView点击分区下拉单元格特效
来源:互联网 发布:java web创意项目 编辑:程序博客网 时间:2024/05/17 04:25
#import "MGMineMenuVc.h"
#import "MGSubSelectVc.h"
#import "HeaderView.h"// 此为自定义的分区视图
#import "PlCustormCell.h" //自定义单元格
staticNSString * const ReuseIdentifierHeader =@"header";
staticNSString * const ReuseIdentifierCell =@"dcell";
@interface MGMineMenuVc ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,copy) MGBasicBlock basicBlock;
@property(nonatomic,strong)UISwipeGestureRecognizer * rightGesture;
@property (nonatomic,strong) UITableView *tableView;
@property(nonatomic,strong)UILabel * lab;
@property(nonatomic,assign)BOOL isPieceSelected;
@property (nonatomic,strong) NSMutableDictionary *dataDic;
@property (nonatomic,strong) NSArray *dataArray;
@property (nonatomic,strong) NSMutableArray *expendArray;//用于记录分区字段的数组
@property (nonatomic,strong) NSMutableArray *selectArray;//用于记录单元格具体字段的数组
@end
@implementation MGMineMenuVc
- (void)viewDidLoad {
[superviewDidLoad];
self.title =@"筛选";
self.isPieceSelected =NO;
UIBarButtonItem *cancelBarItem = [[UIBarButtonItemalloc] initWithTitle:@"取消"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(cancelAction)];
self.navigationItem.leftBarButtonItem = cancelBarItem;
UIBarButtonItem *SureBarItem = [[UIBarButtonItemalloc] initWithTitle:@"确定"style:UIBarButtonItemStyleDonetarget:selfaction:@selector(cancelAction)];
self.navigationItem.leftBarButtonItem = cancelBarItem;
self.navigationItem.rightBarButtonItem = SureBarItem;
[selfloadData];
[selfinitTableView];
self.rightGesture = [[UISwipeGestureRecognizeralloc] initWithTarget:selfaction:@selector(rightGestureRec:)];
[self.viewaddGestureRecognizer:self.rightGesture];
self.rightGesture.direction = UISwipeGestureRecognizerDirectionRight;
}
-(void)rightGestureRec:(UISwipeGestureRecognizer *)sender
{
[selfcancelAction];
}
-(void)loadData
{
NSString *path = [[NSBundlemainBundle] pathForResource:@"role"ofType:@"plist"];
NSMutableArray *wai = [[NSMutableArrayalloc] initWithContentsOfFile:path];
for (int i =0; i < wai.count; i ++)
{
NSArray *list = [wai[i] objectForKey:@"list"];
NSMutableArray *array = [NSMutableArrayarrayWithCapacity:0];
for (int j =0; j < list.count; j ++) {
[arrayaddObject:[list objectAtIndex:j]];
}
[self.dataDicsetObject:array forKey:[wai[i]objectForKey:@"name"]];
}
self.dataArray = [self.dataDicallKeys];
}
-(void)initTableView
{
self.tableView.tableFooterView = [UIViewnew];
[self.tableViewsetTableFooterView:[[UIViewalloc] initWithFrame:CGRectZero]];
self.tableView = [[UITableViewalloc] initWithFrame:CGRectMake(0,0,Screen_weight-kMGLeftSpace,Screen_height)style:UITableViewStyleGrouped];
[self.tableViewregisterClass:[HeaderViewclass] forHeaderFooterViewReuseIdentifier:ReuseIdentifierHeader];
[self.tableViewregisterClass:[PlCustormCellclass] forCellReuseIdentifier:ReuseIdentifierCell];
self.tableView.delegate =self;
self.tableView.dataSource =self;
[self.viewaddSubview:self.tableView];
}
- (void)setCancleBarItemHandle:(MGBasicBlock)basicBlock{
self.basicBlock = basicBlock;
}
- (void)cancelAction{
if(self.basicBlock)self.basicBlock();
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableVie
{
return self.dataArray.count;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
NSString *key = self.dataArray[section];
NSArray *array = self.dataDic[key];
if ([self.expendArraycontainsObject:key]) {
return array.count;
}else {
return 0.0;
}
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
return 44;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
return 0.1;
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
NSString *key = self.dataArray[section];
HeaderView *view = [tableViewdequeueReusableHeaderFooterViewWithIdentifier:ReuseIdentifierHeader];
view.titleLabel.text = key;
view.selectedBtn.tag = section;
[view.selectedBtnaddTarget:selfaction:@selector(headerButtonOnClick:)forControlEvents:UIControlEventTouchUpInside];
[view.tapaddTarget:selfaction:@selector(headerTap:)];
if ([self.expendArraycontainsObject:key]) {
view.icon.transform =CGAffineTransformMakeRotation(M_PI_2);
}else {
view.icon.transform =CGAffineTransformIdentity;
}
return view;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *key = self.dataArray[indexPath.section];
NSArray *array = self.dataDic[key];
NSString *name = array[indexPath.row];
PlCustormCell *cell = [tableViewdequeueReusableCellWithIdentifier:ReuseIdentifierCellforIndexPath:indexPath];
if (cell == nil) {
cell = [[PlCustormCellalloc] initWithStyle:UITableViewCellStyleDefaultreuseIdentifier:ReuseIdentifierCell];
}
if ([self.selectArraycontainsObject:name]) {
cell.selectedImage.selected =YES;
}else {
cell.selectedImage.selected =NO;
}
NSLog(@"tableView.visibleCells.count%lu",(unsignedlong)tableView.visibleCells.count);
cell.backgroundColor = [UIColorlightTextColor];
cell.nameLabel.text = name;
// cell.selectionStyle = UITableViewCellSelectionStyleNone;
return cell;
}
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
NSString *key = self.dataArray[indexPath.section];
NSArray *array = self.dataDic[key];
NSString *name = array[indexPath.row];
NSLog(@"ng)indexPath.section%ld",(long)indexPath.section);
if ([self.selectArraycontainsObject:name]) {
[self.selectArrayremoveObject:name];
}else {
[self.selectArrayaddObject:name];
}
NSIndexSet *sectionIndexSet = [NSIndexSetindexSetWithIndexesInRange:NSMakeRange(0, indexPath.section)];
[self.tableViewreloadSections:sectionIndexSet withRowAnimation:UITableViewRowAnimationNone];
[self.tableViewreloadData];
}
#pragma mark - private methods
- (void)headerButtonOnClick:(UIButton *)button {
NSString *key = self.dataArray[button.tag];
NSArray *array = self.dataDic[key];
if (button.selected) {
[self.selectArrayremoveObjectsInArray:array];
}else {
[self.selectArrayaddObjectsFromArray:array];
}
button.selected = !button.selected;
[self.tableViewreloadSections:[NSIndexSetindexSetWithIndex:button.tag]withRowAnimation:UITableViewRowAnimationNone];
}
- (void)headerTap:(UITapGestureRecognizer *)tap {
HeaderView *view = (HeaderView *)tap.view;
NSString *key = view.titleLabel.text;
NSInteger index = [self.dataArrayindexOfObject:key];
if ([self.expendArraycontainsObject:key]) {
[self.expendArrayremoveObject:key];
[UIViewanimateWithDuration:0.1animations:^{
view.icon.transform =CGAffineTransformIdentity;
}];
}else {
[self.expendArrayaddObject:key];
[UIViewanimateWithDuration:0.1animations:^{
view.icon.transform =CGAffineTransformMakeRotation(M_PI_2);
}];
}
[self.tableViewreloadSections:[NSIndexSetindexSetWithIndex:index] withRowAnimation:UITableViewRowAnimationAutomatic];
}
#pragma mark - getters
- (NSMutableDictionary *)dataDic {
if (!_dataDic) {
_dataDic = [NSMutableDictionarydictionaryWithCapacity:0];
}
return_dataDic;
}
- (NSMutableArray *)expendArray {
if (!_expendArray) {
_expendArray = [NSMutableArrayarrayWithCapacity:0];
}
return_expendArray;
}
- (NSMutableArray *)selectArray {
if (!_selectArray) {
_selectArray = [NSMutableArrayarrayWithCapacity:0];
}
return_selectArray;
}
- iOS tableView点击分区下拉单元格特效
- tableView点击下拉菜单
- iOS tableView分区+索引
- IOS tableview点击跳转
- iOS tableView分区头自定义
- IOS控件TableView下拉刷新
- iOS tableView下拉图片放大
- iOS tableView下拉图片变大
- tableView点击下拉更多的效果
- iOS开发Tableview配置单元格相关内容
- iOS 设置tableView每个分区cell圆角
- IOS小技巧-tableview下拉刷新
- IOS控件 Tableview 下拉刷新,加载数据
- iOS实现tableView下拉搜索功能
- IOS控件 Tableview 下拉刷新,加载数据
- iOS tableView 自带的下拉刷新
- iOS UITableView(十一) tableView的下拉刷新
- iOS——下拉tableview放大图片
- Java Exception 捕获和展示
- 【构】从游戏Buff谈装饰者模式那些事儿
- 前端架构之简洁的工作流
- more--每天一个-02
- Python - 迭代(for...in...:)
- iOS tableView点击分区下拉单元格特效
- 机器学习复习——KNN
- 《C语言程序设计》课后编程题选讲(ch2)
- Python
- Java 动态代理机制分析及扩展
- myeclipse添加使用hibernate框架详解
- EaselJS 事件
- 继续深入网络编程Socket
- 联合体(共同体)