我有一個帶有兩個部分的UITableView
。基於用戶交互(選擇和取消選擇),我的數據源和UITableView
被更新以在部分之間移動數據。最初他們只是0節的數據。當我點擊一個單元格時,willSelectCellAtIndexPath
和didSelectCellAtIndexPath
被調用。正如預期的那樣,當我再次點擊同一個單元時,didDeselectCellAtIndexPath
被調用。當在UITableView中點擊已經選擇的單元格時,將調用willSelectCellAtIndexPath
即使在我開始將數據移動到第1部分並選擇和取消選擇後,UITableView's
委託方法被適當調用。
將所有數據移至第1部分後,UITableView
開始表現出奇怪的行爲。我最初可以選擇一個電話並調用didSelectCellAtIndexPath
。但是,當我再次點擊它時,didDeselectCellAtIndexPath
永遠不會被調用。取而代之的是,選擇的小區上的任何水龍頭(我已經證實它是通過在第1 [tableView indexPathsForSelectedCells]
或任何其他細胞確實只選擇導致willSelectIndexPath
和didSelectIndexPath
獲取調用。
我有相當多的代碼在這些委託方法,其是不相關的(我相信)......我不明確更改單元格的選定狀態的任何地方我已經發布willSelect
方法,必要時可以發佈更多
- (NSIndexPath *)tableView:(UITableView *)tableView willSelectRowAtIndexPath:(NSIndexPath *)indexPath{
if (remainingItemIsSelected && indexPath.section == 0) {
//other cells in the remaining items section are selected and a cell from that section is being selected
NSMutableIndexSet *arrayIndexesToBeDeleted = [[NSMutableIndexSet alloc] init];
for (NSIndexPath *previouslySelectedIndexPath in [tableView indexPathsForSelectedRows]) {
if (((ReceiptItem *)[self.remainingReceiptItems objectAtIndex:previouslySelectedIndexPath.row]).allocated == YES) {
//update data sources
NSLog(@"%@%i%@,%i",@"Section #:",previouslySelectedIndexPath.section,@" Row #:",previouslySelectedIndexPath.row);
[self.assignedReceiptItems addObject:[self.remainingReceiptItems objectAtIndex:previouslySelectedIndexPath.row]];
[arrayIndexesToBeDeleted addIndex:previouslySelectedIndexPath.row];
//update index path arrays
[self.receiptItemsToDeleteIndexPaths addObject:previouslySelectedIndexPath];
[self.receiptItemsToAddIndexPaths addObject:[NSIndexPath indexPathForRow:self.assignedReceiptItems.count-1 inSection:1]];
//update the pressed indexpath to equal to resulting indexpath to pass on to the didSelect method
if (previouslySelectedIndexPath.row < indexPath.row) {
indexPath = [NSIndexPath indexPathForRow:indexPath.row-1 inSection:0];
}
}
}
//Delete assigned items from the remaining receipt items
[self.remainingReceiptItems removeObjectsAtIndexes:arrayIndexesToBeDeleted];
//update table (move allocated item down)
[tableView beginUpdates];
[tableView deleteRowsAtIndexPaths:self.receiptItemsToDeleteIndexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView insertRowsAtIndexPaths:self.receiptItemsToAddIndexPaths withRowAnimation:UITableViewRowAnimationAutomatic];
[tableView endUpdates];
if (self.remainingReceiptItems.count == 0) {
[tableView reloadSections:[NSIndexSet indexSetWithIndex:0] withRowAnimation:UITableViewRowAnimationAutomatic];
}
//other cells in the remaining items section are selected and a cell from assigned items is being selected
return nil;
}
return indexPath;
}
您是否設置了斷點來檢查方法是否被調用?或者你只考慮你的'NSLog()'語句? – CainaSouza 2013-03-13 20:50:42
我設置了斷點並確認沒有調用'didDeselectRowAtIndexPath'。另外,我確認'willDeselectRowAtIndexPath'也沒有被調用。 – IkegawaTaro 2013-03-13 21:37:45