即使我有一个navigationController,pushViewController也无法工作

时间:2012-08-27 10:59:13

标签: iphone objective-c ios xcode cocoa

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

在UIViewController.h中我有,

FirstTableViewController *firstController;
SecondTableViewController *secondController;

在UIViewController.m中我有,

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

答案 0 :(得分: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];

答案 1 :(得分:0)

如果您想以模态方式显示视图控制器,则应使用presentViewController:animated:completion:而不是pushViewController:animated:

[self presentViewController:controller animated:YES completion:nil];

答案 2 :(得分:0)

在“didSelectRowAtIndexPath”

中使用此代码
UIViewController *controller = [[UIViewController alloc]initWithNibName:@"UIViewController" bundle:nil];


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

     [viewController release];

答案 3 :(得分:0)

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

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

[self setNavigationController:navController];

您是否同时识别了两个表格视图?你能在这里发布日志状态吗?

相关问题