2011-06-25 56 views
0

我創建了nib文件,並且正確地完成了所有連接。當我運行應用程序並選擇一個單元格時,新的筆尖根本不打開。請幫忙!爲什麼選擇單元格後視圖筆尖無法打開?

- (void)tableView:(UITableView *)tableView 
didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 

    //Get the selected country 
NSString *selectedCountry = [[NSString alloc] initWithFormat:@"you pressed for this."]; 

//Initialize the detail view controller and display it. 
DetailViewController *dvController = [[DetailViewController alloc] 
             initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]]; 

dvController.selectedCountry = selectedCountry; 
[self.navigationController pushViewController:dvController animated:YES]; 
[dvController release]; 
dvController = nil; 

} 
+0

發佈'selectedCountry'或者你泄漏。它在導航控制器上嗎?在'pushViewController:animated:'方法後立即嘗試'NSLog(@「%@%@」,self.navigationController,dvController);'讓我們知道結果。 –

+0

你會得到哪個錯誤?也'dvController =零;'不需要,因爲你之前從內存中刪除dvController。 – sherilyn

+0

@Deepak,我在DetailViewController.m中發佈了selectedCountry,並試着告訴我,但沒有運氣! – Jovany

回答

0

試試這個:


DetailViewController *dvController = [[DetailViewController alloc] 
             initWithNibName:@"DetailView" bundle:[NSBundle mainBundle]]; 

dvController.selectedCountry = selectedCountry; 
[self.navigationController pushViewController:dvController animated:YES]; 
dvController = nil; 
+0

發佈是遵守內存管理規則所必需的。 –

0

不能同時釋放dvController並將其設置爲nil - 只做一個。

+1

只是爲了重申,釋放是遵守內存管理規則所必需的。然而'無'是不必要的。 –

3

它看起來像(根據NSLog聲明沒有記錄輸出)您沒有正確設置delegate,因爲它會以其他方式記錄null或某個對象值。你需要重新檢查你的IB連接,或者如果你以編程的方式完成,那麼做tableView.delegate = self;

0

希望你試圖從listviewcontroller加載detailvewcontroller。表視圖是listviewcontroller的成員。

問題的可能原因。

如果添加listviewcontroller.view作爲一個子視圖的任何其他viewcontollers查看然後

[self.navigationController pushViewController:dvController動畫:YES];不工作。

因此,您應該獲得應用程序委託的實例並執行以下操作。

YourAppDelegate *appDelegate = (YourAppDelegate *)[[UIApplication sharedApplication] delegate]; 

[appDelegate .navigationController pushViewController:dvController animated:YES]; 

檢查一下。如果這不是您的問題的原因,請讓我知道控制檯輸出Deepak問你。

相關問題