2013-10-11 17 views
0

編輯:我解決了這個問題。該代碼已更正以顯示此修復程序。必須按兩次詳細披露按鈕才能通過使用prepareForSegue方法的數據

我有一個使用UITableViewController的應用程序,它顯示按字母順序分割爲各個部分的所有50個狀態的列表。我已將細節泄露按鈕添加到故事板中的原型單元格,並且表格顯示所有正確的信息。

當我按下單元格上的按鈕時,它應該延續到一個新的viewController並顯示狀態的名稱作爲視圖標題,然後在視圖中顯示牌照的圖片。我使用的是 - (void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath方法來控制按鈕然後我使用 - (void)prepareForSegue :(UIStoryboardSegue *)segue sender :(id)sender來控制傳遞給新viewController的值。

我遇到的問題是,當我按詳細披露按鈕時,沒有任何東西可以通過。 NSLogging在新的viewController輸出值(空),(null)和視圖沒有標題或圖片。但是,當我按回來,然後再次按下同一個單元格的詳細信息披露按鈕時,它的工作方式應該如此。標題正確,圖片正確顯示。

當我選擇另一個單元時,viewController顯示發送的最後一個信息,我必須再次按回來,然後再次選擇該單元以更新。當第一次選擇不同的單元格時,(null,(null)是NSlog輸出的內容,所以我相信發生的事情是,第一次按下詳細信息按鈕時,沒有值被傳遞,但第二次它被按下時,值被傳遞

下面是相關代碼:。

-(void)tableView:(UITableView *)tableView accessoryButtonTappedForRowWithIndexPath:(NSIndexPath *)indexPath 
{ 
    //Don't even use this method now. 
} 

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender 
{ 
UITableViewCell *cell = (UITableViewCell*)sender; //Added this line 
self.path = [self.tableview indexPathForCell:cell]; //Added this line 

if ([segue.identifier isEqualToString:@"stateSegue"]) 
    { 
     self.controller = segue.destinationViewController; 
     self.controller.stateName = [self.stateArray[indexPath.section][indexPath.row]stateName]; 
     self.controller.licensePlateURL = [self.stateArray[indexPath.section][indexPath.row]licensePlateURL]; 
    } 
} 

任何幫助,將不勝感激

回答

0

檢查方法首先解僱也許你設置屬性哪個。在執行完賽後

沒有關於如何執行賽格的信息。

您可以將該行添加到您的accessoryButton方法:

[self performSegueWithIdentifier:yourIdentifierFromStoryboard sender:self]; 
+0

其實我想通了這部分了。我甚至不再使用accessoryButtonTapped方法。我編輯了我的代碼以顯示工作的「方法」。 – razielxx

相關問題