【问题标题】:pushViewController doesnt work even though i have a navigationController即使我有一个 navigationController,pushViewController 也不起作用
【发布时间】:2012-08-27 10:59:12
【问题描述】:

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

【问题讨论】:

  • [self navigationController] 是否返回 nil
  • 没有。它返回

标签: iphone objective-c ios xcode cocoa


【解决方案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];

【讨论】:

  • 不起作用,因为 UIViewController 不是我的第一个 ViewController。 UIViewController 从 UtilityApp 的 FlipsideView 调用。
  • 您能否检查一下您推送的 viewController 是否为 nil。
【解决方案2】:

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

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

【讨论】:

  • 不.. 我需要推送它.. 因为它们是 DetailViewControllers。当我尝试以模态方式呈现它时,我收到以下错误应用程序试图以模态方式呈现一个活动控制器
  • 你加载的控制器也不为零?
  • 没有。它的
【解决方案3】:

在“didSelectRowAtIndexPath”中使用此代码

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


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

     [viewController release];

【讨论】:

    【解决方案4】:

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

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

    您是否确定了两个表视图?你能在这里发布日志状态吗?

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-09-04
      • 2020-02-06
      • 1970-01-01
      • 2019-06-17
      • 1970-01-01
      • 2021-04-05
      相关资源
      最近更新 更多