2014-01-17 26 views
3

我有一個父表視圖與自定義行,每個人推視圖控制器tableview的可選選項,作爲父視圖控制器的屬性存儲。我的代碼:爲什麼我的tableview不會調用didselectrowatindexpath直到第二次觸摸?

- (void) tableView:(UITableView *)tableView didDeselectRowAtIndexPath:(NSIndexPath *)indexPath { 
    /* 
    CrewPositions *selectedPosition = (self.crewPositionList)[indexPath.row]; 
    [self.delegate childCrewPositionDidSelect:selectedPosition]; 
    NSLog(@"child Selected Position: %@", selectedPosition.title); 
    [[self navigationController] popViewControllerAnimated:YES]; 
    */ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    cell.accessoryType = UITableViewCellAccessoryCheckmark; 

    CrewPositions *selectedPosition = (self.crewPositionList)[indexPath.row]; 
    self.selectedCrewPosition = selectedPosition; 
    NSLog(@"self.selectedCrewPosition: %@", self.selectedCrewPosition); 
    selectedFlightHistory.crewPosition = selectedPosition; 
    NSLog(@"self.selectedFlightHistory.crewPosition: %@", selectedFlightHistory.crewPosition.title); 

    [self.delegate childCrewPositionDidSelect:selectedPosition]; 

    NSLog(@"Popping view to parent"); 
    [self.navigationController popViewControllerAnimated:YES]; 
} 

正常工作,遺憾的是該方法didSelectRowAtIndexPath不會被調用,直到後,我拼接單元的列表中的第二次。當我這樣做時,它將先前選擇的第一行傳遞給父視圖。忽略大量的NSLog,只是捕獲變量正在做的事情。

+0

是的 - 如果您閱讀正在實施的委託方法的名稱,它會有所幫助。 – Abizern

回答

8

didDeselectRowAtIndexPath方法重新命名爲didSelectRowAtIndexPath

它被稱爲在第二次,因爲你選擇另一個單元格,並取消前一個

+0

噢,我的上帝,我瞎了! –

+3

你不是第一個犯了這個錯誤... –

+1

而你不會是最後一個 - (免責聲明 - 我已經做了幾次) – Abizern

2

,它的發生是因爲你寫錯誤的方法名。 didDeselectRowAtIndexpath:當行是de - 被選中時發送。

因此,更改方法名稱didSelectRowAtIndexPath:以便實現正確的委託方法。

+0

不要重複的答案。 – rmaddy

相關問題