" moveRowAtIndexPath"如果我选择一行或移动一个uitableview,则会调用它

时间:2015-08-19 05:02:14

标签: ios objective-c uitableview

我需要在didSelectRowAtIndexPath按钮的moveRowAtIndexPathUITableView方法之间进行检测,但我发现当我在[myTableView setEditing:YES animated:YES]设置ViewDidLoad时,我是否选择或者继续将单元格移动到moveRowAtIndexPath。我真的想要检测两种方法,以便在敲击或移动细胞时进行不同的治疗。

这是我的代码:

- (void)viewDidLoad {
    [super viewDidLoad];
    [HomeTableView setEditing:YES animated:YES];
    [HomeTableView setScrollEnabled:NO];
}

- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)sourceIndexPath toIndexPath:(NSIndexPath *)destinationIndexPath {
    //it's always get here when i select on cell
    //do something here
}

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
    if (indexPath.row == 0) // Don't move the first row
    {
        return NO;
    }
        return YES;
}

-(BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
    return YES;
}

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    //i wanna do thing here but it's never into this method when i set [HomeTableView setEditing:YES animated:YES];
}

任何帮助都是值得的。提前谢谢......

2 个答案:

答案 0 :(得分:1)

您需要将UITableView的allowsSelectionDuringEditing属性设置为true ..

self.tableView.allowsSelectionDuringEditing=YES;

答案 1 :(得分:0)

UITableView上有一个属性,允许在编辑模式下选择行。您可以在storyboardSingle Selection During Editing或代码中将allowsSelectionDuringEditing属性设置为YES