//1、 是否支持移動(dòng)
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
//2奏寨、 移動(dòng)行操作
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath{
// 這里其實(shí)就是數(shù)組中兩個(gè)變量交換位置的過程 id object = [self.dataArray objectAtIndex:fromIndexPath.row];
[self.dataArray removeObjectAtIndex:fromIndexPath.row];
[self.dataArray insertObject:object atIndex:toIndexPath.row];
}
cell側(cè)滑
- (NSArray *)tableView:(UITableView *)tableView editActionsForRowAtIndexPath:(NSIndexPath *)indexPath{
NSString *topTitle ,*readTitle;
XZGroup *group = self.dataArray[indexPath.row];
topTitle = group.isTop ? @"取消置頂" : @"置頂";
readTitle = group.unReadCount ? @"標(biāo)為已讀" : @"標(biāo)為未讀";
//設(shè)置刪除按鈕
UITableViewRowAction * deleteRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:@"刪除" handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
[self deleteLocalGroupWithIndexPath:indexPath];
}];
//置頂
UITableViewRowAction * topRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:topTitle handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
[self setTopCellWithIndexPath:indexPath currentTop:group.isTop];
}];
//標(biāo)記已讀
UITableViewRowAction * collectRowAction = [UITableViewRowAction rowActionWithStyle:UITableViewRowActionStyleDefault title:readTitle handler:^(UITableViewRowAction * _Nonnull action, NSIndexPath * _Nonnull indexPath) {
[self markerReadWithIndexPath:indexPath currentUnReadCount:group.unReadCount];
}];
collectRowAction.backgroundColor = [UIColor grayColor];
topRowAction.backgroundColor = [UIColor orangeColor];
return @[deleteRowAction,topRowAction,collectRowAction];
}