*****多选删除*****
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
//2个一起返回,就是多选删除模式
return UITableViewCellEditingStyleDelete | UITableViewCellEditingStyleInsert;
}
思路
【一】,设一个可变数组arr,当处于编辑状态时每选中一个cell就添加一个数据到arr中,反选一个就删除一个
【二】,在编辑方法中清除arr中的内容
//self.editButtonItem系统自带的编辑按钮
//使用系统自带的编辑按钮时必须让父类重载编辑方法
-(void)setEditing:(BOOL)editing animated:(BOOL)animated
{
[super setEditing:editing animated:animated];
[_myTableView setEditing:editing animated:animated];
}
【三】,设一个button或其它有点击事件的view,在点击事件中将arr里的对象从数据源中删除,然后重载tableView
*****搜索*****
【一,索引】
//为tableView设置索引
//NSArray (存放索引标题的数组)
- (NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
//UITableViewIndexSearch 系统内置的字符串,会显示成一个放在镜
NSMutableArray *arr = [[NSMutableArray arrayWithObject:UITableViewIndexSearch];
//do something
return arr;
}
- (NSInteger)tableView:(UITableView *)tableView sectionForSectionIndexTitle:(NSString *)title atIndex:(NSInteger)index
{//因为索引的前面加了个搜索小图标,所以需要重写这个方法点击的时候要返回的数要-1
return index-1;
}
【二,搜索】
//搜索条被激活时会自动出现在导航条上
一,创建UISearchBar和UISearchDisplayController
_sb = [[UISearchBar alloc]initWithFrame:CGRectMake(0, 0, 320, 44)];
_tv.tableHeaderView = _sb;
_sdc = [[UISearchDisplayController alloc]initWithSearchBar:_sb contentsController:self];
_sdc.delegate = self;
_sdc.searchResultsDelegate = self;
_sdc.searchResultsDataSource = self;
二,【UISearchDisplayDelegate】
- (BOOL)searchDisplayController:(UISearchDisplayController *)controller shouldReloadTableForSearchString:(NSString *)searchString
{//在搜索框里输入的时候触发
[_resultArr removeAllObjects];
for (NSMutableArray *marr in _dataArr) {
for (NSString *str in marr) {
NSRange ran = [str rangeOfString:searchString];
if (ran.length) {
[_resultArr addObject:str];
}
}
}
return YES;
}
三,搜索结果展示会自动创建一个新的tableView,用的也是tableView的代理,所以需要在所有的代理中判断现在是搜索结果,还是原来的tableview
折叠,展开
思路:
1,设置一个可变数组记录每一分区的展开状态,点击每一行的headView的时候就改变这一分区的展开状态,然后重载这一段
[_tv reloadSections:[NSIndexSet indexSetWithIndex:sender.tag-1000] withRowAnimation:UITableViewRowAnimationAutomatic];
2,在numberOfRowsInSection里判断展开状态,如果是展开状态就正常显示,如果是折叠状态就返回0