2010-08-18 45 views
0

我有一個問題,我在測試中工作,但現在在一個更大的應用程序中,我似乎無法理清。didSelectRowAtIndexPath問題

我首先有一個有六個按鈕,每一個加載我使用的是不同的視圖中的視圖:

- (IBAction)showInfo2:(id)sender { 
InfoViewController *Infocontroller = [[[InfoViewController alloc] initWithNibName:@"InfoView" bundle:nil] autorelease]; 
Infocontroller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve; 
[self presentModalViewController:Infocontroller animated:YES]; 
} 

這似乎是工作的罰款,並加載下一個部分,在這種情況下「的InfoView」。 然後,我加載一個tableview,並從一個xml feed中填充完整的f數據,這又是一個工作,(儘管對我來說不是一件容易的事情!)。

問題出現在我知道嘗試和使用時: 似乎沒有發生任何事情,即新視圖未加載。

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

// Navigation logic may go here -- for example, create and push another view controller. 
SubInfoViewController *subInfoViewController = [[SubInfoViewController alloc] initWithNibName:@"SubInfoView" bundle:nil]; 
[self.navigationController pushViewController:subInfoViewController animated:YES]; 
[subInfoViewController release]; 
} 

我知道它被調用,因爲這個工程:

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

NSString *message = [[NSString alloc] initWithFormat:@"You selected a row"]; 
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Row Selected" message:message delegate:nil cancelButtonTitle:@"Yes I did" otherButtonTitles:nil]; 
[alert show]; 

[message release]; 
[alert release]; 
} 

任何幫助多人歡迎,並請溫柔新手:)

回答

2

您正在查看的可能是推入導航堆棧,但您無法看到它,因爲您的父視圖是模態的。

你不能試圖顯示您的SubInfoViewController這樣的:

SubInfoViewController *subcontroller=[[SubInfoViewController alloc] initWithNibName:@"SubInfoViewController" withBundle:nil]; 
[self presentModalViewController:subcontroller animated:YES]; 
[subcontroller release]; 

如果你想保持一個導航邏輯在您的應用程序,你不應該有模式地顯示你的InfoViewController但在一個共同的方式展示它您的導航堆棧。

在推送您的SubViewController之前,您可以嘗試解除您的模態視圖。在這種情況下,你必須做這樣的事情:

SubInfoViewController *controller=[[SubInfoViewController alloc] initWithNibName:@"SubInfoViewController" bundle:nil]; 
[self.parentViewController pushViewController:controller animated:YES]; 
[self dismissModalViewControllerAnimated:YES]; 
[controller release]; 

您會收到一個警告,因爲parentViewController可能不pushViewController: animated:迴應,但有NSLog,你會看到你的parentViewController實際上是一個UINavigationController

希望這會有所幫助!

0

到底是什麼問題?乍一看,你的代碼看起來很好。

+0

對不起,它的pushview控制器似乎並沒有加載新視圖。 – jimbo 2010-08-18 08:33:09