1

我有一个 UIViewController,里面有两个 UITableView。当我在第一个 UITableView 中选择一行时,它必须推送不会发生的相同 UIViewController。

在 UIViewController.hi 中有,

FirstTableViewController *firstController;
SecondTableViewController *secondController;

在 UIViewController.mi 中有,

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    if (firstController == nil) {
        firstController = [[FirstTableViewController alloc] init];
    }
    if (secondController == nil) {
        secondController = [[SecondTableViewController alloc] init];
    }
    UINavigationController *firstNavigationController = [[UINavigationController alloc] initWithRootViewController:firstController];
    firstController.product = self.product;
    [firstTable setDataSource:firstController];
    [firstTable setDelegate:firstController];
    firstNavigationController.view = firstController.tableView;
}

在 FirstTableViewController.m 中,我有 didSelectRowAtIndexPath,

[self.searchDisplayController setActive:YES animated:YES];
UIViewController *controller = [[UIViewController alloc]initWithNibName:@"UIViewController" bundle:nil];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
controller.product = prod;
NSLog(@"Navigation controller is %@",self.navigationController); //not null
[[self navigationController]pushViewController:controller animated:YES];

请帮忙。

编辑#1:从 UtilityApp 的 FlipsideViewController 调用 UIViewController。

4

4 回答 4

1

向您的 AppDelegate 添加一个属性UINavigationController *nav 在应用程序 didFinishLaunching 方法中将此行添加到 AppDelegate.m

navigationControl = [[UINavigationController alloc] initWithRootViewController:yourFirst ViewController];

转到 yourFirstViewController,添加一个UINavigationController *nav属性并将这些行添加到 viewDidLoad 方法

AppDelegate *app = [[UIApplication sharedApplication] delegate];
self.nav = app.nav;

使用此行推送任何 viewController

[self.nav pushViewController:controller animated:YES];
于 2012-08-27T11:27:07.513 回答
0

LoginViewSimpleController *loginViewSimple = [[LoginViewSimpleController alloc]init];

UINavigationController *navController = [[UINavigationController alloc]initWithRootViewController:loginViewSimple];

[self setNavigationController:navController];

Have you identify both tableviews ? Can you Post log status here ?

于 2012-08-27T11:47:04.467 回答
0

在“didSelectRowAtIndexPath”中使用此代码

UIViewController *controller = [[UIViewController alloc]initWithNibName:@"UIViewController" bundle:nil];


     [self.navigationController pushViewController:controller animated:YES];

     [viewController release];
于 2012-08-27T11:08:06.717 回答
0

如果你想以模态方式显示视图控制器,你应该使用presentViewController:animated:completion:and not pushViewController:animated:

[self presentViewController:controller animated:YES completion:nil];
于 2012-08-27T11:03:16.863 回答