didSelectRowAtIndexPath问题

时间:2010-08-18 08:24:46

标签: objective-c iphone uitableview

我有一个问题,我在测试中工作,但现在在一个更大的应用程序中我似乎无法解决。

首先我有一个视图,其中有六个按钮,每个按钮加载我正在使用的不同视图:

- (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 个答案:

答案 0 :(得分: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 }。

希望这有帮助!

答案 1 :(得分:0)

究竟是什么问题?乍一看你的代码看起来很好。