當UITableView 在編輯狀態時,點擊cell,不調用didSelectedRowAtIndexPath解決辦法

當UITableView 在編輯狀態時,點擊cell,不調用didSelectedRowAtIndexPath.

問題代碼:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath  {
    if (self.tableView.editing == YES)  {
        NSLog(@"now in editing mode");
    }
    else {
        NSLog(@"now in normal mode");
    }
}

- (void)setEditing:(BOOL)editing animated:(BOOL)animated  {
    [super setEditing:editing animated:animated];
    // must be called first according to Apple docs
    [self.tableView setEditing:editing animated:animated];
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath  {
    // Return NO if you do not want the specified item to be editable.
    return YES;
}

- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath  {
    return UITableViewCellEditingStyleNone;
}

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath  {
    return NO;
}

以上代碼編輯狀態下點擊cell,無法調用-didSelectedRowAtIndexPath方法打印"now in editing mode"。

解決方法:
將UITableVIew 的屬性 allowsSelectionDuringEdinting 設置爲 TRUE,之後就可在編輯模式下,調用點擊方法了。

self.tableView.allowsSelectionDuringEditing=YES;

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章