gpt4 book ai didi

iphone - pushViewController 不工作,即使我有一个 navigationController

转载 作者:行者123 更新时间:2023-11-29 13:29:56 25 4
gpt4 key购买 nike

我有一个 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。

最佳答案

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

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

转到您的 FirstViewController,添加 UINavigationController *nav 属性并将这些行添加到 viewDidLoad 方法

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

使用这一行来推送任何viewController

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

关于iphone - pushViewController 不工作,即使我有一个 navigationController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12140702/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com