iOS UITableView2
来源:互联网 发布:热血战歌龙心升级数据 编辑:程序博客网 时间:2024/05/17 21:54
1 单元格的编辑
本身自带刷新 你用自己的方法刷新的时候要注意
//—————-编辑多选模式—————–
//1.首先在我们的头试图上增加一个button,用于控制tableView是否处于编辑状态
//2.设置哪些单元格可以编辑,哪些单元格不能编辑,默认可编辑
//3.设置每个单元格的编辑模式下的按钮样式(新增和删减),默认删除
//4.在commitEditing方法里增加加减少,要使用_dataLIte,使用reloadData或者增加cell的方法实现
//5.设置可移动
//6.移动的位置调整,先取下来,删除原位置,增加插入新围智
(void)editButtonAct:(UIButton *)button{
button.selected = !button.selected;
if(button.selected == YES){
[tableView setEditing:YES animated:YES];
}else{
[tableView setEditing:NO animated:YES];
}
}
2 单元格移动
首先可以被编辑
(BOOL)tableView:(UITableView )tableView canMoveRowAtIndexPath:(NSIndexPath )indexPath{
return YES;
}(void)tableView:(UITableView )tableView moveRowAtIndexPath:(NSIndexPath )sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
//保存元数据
NSMutableArray *arrayS = rootArray[sourceIndexPath.section];NSString *str = arrayS[sourceIndexPath.row];
//删除原位置的数据
[rootArray[sourceIndexPath.section] removeObjectAtIndex:sourceIndexPath.row];//插入新位置的数据
[rootArray[destinationIndexPath.section] insertObject:str atIndex:destinationIndexPath.row];//刷新
[tableView reloadData];
}
3谓词搜索
1.tableView 首先要看有没有谓词搜索
2.做谓词搜索时 首先要设两个根数组 一个新数组不可变 一个旧数组可变
3.数组 filter谓词 要分清对那一个数组做 是对root数组做还是对root数组的数组做 可以先打印出来看一看
reason: ‘Can’t do regex matching on object 就是找错了数组
4.对Root数组的数组做谓词 可以使用for_in循环 这样就不止距现在在只对组做谓词搜索
//============谓词搜索
(void)textChange{
NSString str = [NSString stringWithFormat:@”self like [C] ‘%@*’”,sort.text];
NSPredicate *predict = [NSPredicate predicateWithFormat:str];
NSMutableArray *array3 = [[NSMutableArray alloc]initWithCapacity:1];
for(NSMutableArray *array in root){
NSArray *array1 = [array filteredArrayUsingPredicate:predict];if(array1 != NULL){ [array3 addObject:array1];}
}
rootArray = [[NSArray alloc]initWithArray:array3];
[tableView reloadData];
}
//设置行高
==去掉没有的组头视图
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
NSArray *array = rootArray[section];if(array.count == 0){ return 0;}else{ return 30;}
}
//快捷搜索
手打一下这个方法 博客不显示返回值
- sectionIndexTitlesForTableView:(UITableView *)tableView{
return@[@"1",@"2",@"3",@"4",@"5",@"6",@"7",@"8"];
// @[@”1”,@”2”,@”3”,@”4”,@”5”,@”6”,@”7”,@”8”,@”9”,@”10”,@”11”,@”12”]; 跟前面的组数一直
}
4点击头视图收起section
BOOL isSelect[100];
-(UIView )tableView:(UITableView )tableView viewForHeaderInSection:(NSInteger)section{
UIView *view = [[UIView alloc]init];UIButton *label = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 375, 30)];[label setTitle:[NSString stringWithFormat:@" 第%ld组",(long)section] forState:UIControlStateNormal];label.backgroundColor = [UIColor yellowColor];[view addSubview:label];[label setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];view.backgroundColor = [UIColor cyanColor];[label addTarget:self action:@selector(headerSevtionButtonAct:) forControlEvents:UIControlEventTouchUpInside];label.tag = 100+section;return view;
}
(void)headerSevtionButtonAct:(UIButton *)button{
isSelect[button.tag - 100] = ! isSelect[button.tag - 100];
[tableView reloadData];
}(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
if(isSelect[section] == NO){
NSArray *array = rootArray[section];return array.count;
}else{
return 0;
}
}
- iOS UITableView2
- UI基础-iOS黑马-UITableView2-单组数据展示 LOL
- UITableView2 - 复用的理解和cell的创建
- iOS
- iOS
- IOS
- iOS
- iOS
- IOS
- ios
- iOS
- iOS
- IOS
- iOS
- ios
- ios ~~~~~
- ios
- IOS
- HDU 2841 容斥原理
- 排序算法-及其Java代码实现
- 轮换相乘的小程序
- JSP开发模式
- 2016-03-28缓存
- iOS UITableView2
- MFC ado 连接sql server提示未知错误
- UI控件--ViewPager详解带Tab交互的ViewPager(5)
- vitamio for android的使用
- android 与后台交互的两种方式xml和json
- Leetcode 111. Minimum Depth of Binary Tree My Submissions QuestionEditorial Solution
- Maven配置
- C++实验2-项目1标准体重
- 项目14-三角形类雏形(3)