在创建早期表后添加新的起始视图 - 不起作用

时间:2012-10-30 22:42:34

标签: iphone objective-c xcode uitableview uiviewcontroller

我正在使用UIKit元素和xib文件开发一些应用程序。首先,我创建了包含表和详细视图的主详细信息应用程序。我已经定制了细胞和细节视图,一切都很好。然后我想添加一个新视图,它的行为就像用户将看到的第一个视图一样。我创建了新视图,然后想要将其添加到app委托,就像添加了主视图一样。它工作但细节视图不起作用,我不知道为什么。这里有一些代码可以让它更清晰。

的AppDelegate:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[self customizeAppearance];
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
HomeScreenViewController *homescr = [[HomeScreenViewController alloc]initWithNibName:@"HomeScreenViewController" bundle:nil];
self.navigationController = [[UINavigationController alloc] initWithRootViewController:homescr];
self.window.rootViewController = self.navigationController;
[self.window makeKeyAndVisible];
return YES;
}

我的新第一个视图有一个按钮:

- (IBAction)goToTableView:(id)sender {
MasterViewController *tableView = [[MasterViewController alloc]initWithNibName:@"MasterViewController" bundle:nil];
[self presentViewController:tableView animated:YES completion:nil];
}

它转到masterViewController和显示表。然后我点击表中的每个元素没有任何反应。

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath*)indexPath
{
NSLog(@"did select is up");
if (!self.detailViewController) {
    self.detailViewController = [[DetailViewController alloc] initWithNibName:@"DetailViewController" bundle:nil];
}
NSDate *object2 = [array1 objectAtIndex:[indexPath row]];
self.detailViewController.detailItem = object2;
[self.navigationController pushViewController:self.detailViewController animated:YES];
}

NSLog显示信息,但不显示详细视图。此外,navigationController显示在第一个视图中,在表视图中不可见。

有人能告诉我我做错了吗?

提前致谢:)

1 个答案:

答案 0 :(得分:2)

为什么不在goToTableView方法中推送堆栈视图tableView。在那次改变之后,一切都应该有效:

- (IBAction)goToTableView:(id)sender {
    MasterViewController *tableView = [[MasterViewController alloc]initWithNibName:@"MasterViewController" bundle:nil];
    [self.navigationController pushViewController:tableView animated:YES];
}

有关详细信息,请参阅此主题:pushing on modal View