2012-04-29 37 views
13

之前,我試圖改變細胞行爲: 1)當電池輸出,馬克細胞帶有複選標記 2)詳細披露配件按鈕被竊聽的完整,執行Segue。 3)的tableView:didSelectRowAtIndexPath方法:我有:在iOS應用中,爲什麼會出現prepareForSegue didSelectRowAtIndexPath方法

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath 
{ 
    UITableViewCell *cell = [tableView cellForRowAtIndexPath:indexPath]; 
    AWDelivery *delivery = [self.fetchedResultsController objectAtIndexPath:indexPath]; 
    [delivery toggleDelivered: delivery]; 
    [self configureCheckmarkForCell:cell withDelivery:delivery]; 
    [tableView deselectRowAtIndexPath:indexPath animated:YES]; 
    if (debugging) NSLog(@"[%s] [%d]", __PRETTY_FUNCTION__, __LINE__); 
} 

的deselectRowAtIndexPath應該繞過SEGUE,但事實並非如此。

NSLogs: 一)在2012-04-29 18:50:00.848交貨[3148:FB03] [ - [DeliveryTVC prepareForSegue:發送方:]] [168] b)中在2012-04-29 18: 50:01.245 Delivery [3148:fb03] [ - [DeliveryTVC tableView:didSelectRowAtIndexPath:]] [93]

請注意'didSelect'發生在'prepareForSegue'之後。

任何提示將是非常讚賞。

+0

能否請您分享您的代碼。我有同樣的問題。謝謝。 – applefreak

+0

非常隨機,但從您的代碼示例中,我瞭解到__PRETTY_FUNCTION__和__LINE__宏。謝謝! – Guven

回答

14

你有你詳細SEGUE附着在表格視圖單元格?相反,請嘗試在兩個視圖控制器(包含表格和您想要的表格)之間拖動它。

然後手動執行它([self performSegueWithIdentifier:@"MySegue"];)時tableView:accessoryButtonTappedForRowWithIndexPath:

+1

正確的錢!!!!!!!這個小事實應該更明顯。 – JJW

+0

請你可以添加一些代碼手動執行segue請!我有一個同樣的問題,我想將細胞信息傳遞給下一個視圖控制器。你的意思是手動演示模態視圖控制器還是prepareforsegue方法?謝謝。 – applefreak

+1

當然,無論你需要在視圖控制器中,說:[self performSegueWithIdentifier:@「MySegue」];該字符串應該與您在IB中爲segue設置的標識符相匹配。讓我知道你是否需要更多細節。 – danh

6

如果你需要得到prepareForSegue當前的tableview的選擇,你可以通過訪問的UITableViewController的伊娃的tableView得到它;

[self tableView] indexPathForSelectedRow] 
+0

點擊附件按鈕不會選擇單元格,因此indexpath.row不對應於分接附件的正確單元格。 – swampf0etus

1
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
    // Make sure your segue name in storyboard is the same as this line 
    if ([[segue identifier] isEqualToString:@"ClaimDetailsSeque"]) 
    { 
     DLog(@"destinationViewController %@",[[segue destinationViewController] topViewController]); 
     //This syntax is needed when the seque is going through a Navagation Controller 
     ClaimDetailsFormViewController* vc = (ClaimDetailsFormViewController*)[[segue destinationViewController] topViewController]; 

     //This the the way to get the object from the selected row via the FetchedResultsController 
     //this is needed because prepareForSegue is called before didSelectRowAtIndexPath 
     NSIndexPath *selectedIndexPath = [self->claimTableView indexPathForSelectedRow]; 
     ClaimHistory *object = [[self claimHistoryFetchedResultsController] objectAtIndexPath:selectedIndexPath]; 

     MyClaimHistorySM *myCH = [MyClaimHistorySM new]; 

     myCH.policyNumber = object.policyNumber; 
     myCH.policyStatus = object.policyStatus; 
     myCH.claimNumber = object.claimNumber; 
     myCH.insuredName = object.insuredName; 
     myCH.lossDescription = object.lossDescription; 
     myCH.dateOfLoss = object.dateOfLoss; 
     myCH.incidentCloseDt = object.incidentCloseDt; 

     vc.claimHistorySM = myCH; 

    } 

} 

Seque on Storyboard

+0

通過選擇表格視圖單元並將觸發分段選擇「連接器」拖動到導航控制器,在IB中創建了segue。 –

相關問題