{
return YES;
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleDelete;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
CarGroupModel *carGroup = self.carGroupArray[indexPath.section];
if (editingStyle == UITableViewCellEditingStyleDelete) {
[carGroup.cars removeObjectAtIndex:indexPath.row];
}
[self.tableView reloadData];
}
#pragma mark - 可插入數據
-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
-(UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath
{
return UITableViewCellEditingStyleInsert;
}
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{
CarGroupModel *carGroup = self.carGroupArray[indexPath.section];
CarModel *car = [[CarModel alloc]init];
car.name = @"1111";
if (editingStyle == UITableViewCellEditingStyleInsert) {
[carGroup.cars insertObject:car atIndex:indexPath.row];
}
[self.tableView reloadData];
}
#pragma mark - 可移動
-(BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
-(void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath
{
CarGroupModel *carGroupS = self.carGroupArray[sourceIndexPath.section];
[carGroupS.cars exchangeObjectAtIndex:destinationIndexPath.row withObjectAtIndex:sourceIndexPath.row];
}
#pragma mark - 可複製可粘貼
-(BOOL)tableView:(UITableView *)tableView shouldShowMenuForRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
-(BOOL)tableView:(UITableView *)tableView canPerformAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
return YES;
}
-(void)tableView:(UITableView *)tableView performAction:(SEL)action forRowAtIndexPath:(NSIndexPath *)indexPath withSender:(id)sender
{
CarGroupModel *carGroup = self.carGroupArray[indexPath.section];
CarModel *car = carGroup.cars[indexPath.row];
if (action == @selector(copy:)) {
[UIPasteboard generalPasteboard].string = car.name;
}
if (action == @selector(paste:)) {
NSString *name = [UIPasteboard generalPasteboard].string;
car.name = name;
// [self.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationLeft];
[self.tableView reloadData];
}