Iphone 应用程序未导航到第二个视图

Iphone 应用程序未导航到第二个视图,iphone,objective-c,ios,Iphone,Objective C,Ios,我正在使用的代码 NSLog(@"before Navigate to second activity"); Signature *temp = [[Signature alloc]initWithNibName:@"Signature" bundle:nil]; [self.navigationController pushViewController:temp animated:YES]; NSLog(@"after Navigate to second a

我正在使用的代码

  NSLog(@"before Navigate to second activity");
    Signature *temp = [[Signature alloc]initWithNibName:@"Signature" bundle:nil];

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

     NSLog(@"after Navigate to second activity");

在控制台上,两个日志语句都被打印出来,但我的应用程序没有将我导航到下一个视图。请更正。

我认为您的应用程序没有使用navigationController,因此在AppDelegate.m文件中,像这样分配rootViewController

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

然后检查它的工作情况。

日志消息无论如何都会显示出来,所以这并不奇怪。为该导航控制器的代理添加回调(当然,您必须首先设置一个代理)


在那里,您可以确保viewController已通过(确保签名是viewController实例)

如果您没有在应用程序上使用
UINavigationController
,则不能调用
pushViewController
,请改用
presentViewController:animated:completion:

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

有关更多信息,请查看

CreditsViewController*viewController=[[CreditsViewController alloc]init]

[[self-navigationController]pushViewController:viewController动画:是]

[视图控制器释放]


您可以尝试使用上述代码检查
self.navigationController
是否为
nil
。您是正确的。self.navigationController为null。@onkar这是null bcoz您没有为rootviewcontroller分配导航控制器,因此请查看我的代码并分配导航控制器尝试使用您的控制器只是更改名称好,你有导航控制器吗?如果你没有使用ARC,你正在泄漏navviewController。这里的ARC自动释放和释放(自动更正)不起作用,所以如果我们使用带有自动释放的NavigationController,那么这里我们的应用程序崩溃了。所以使用ivar,为你的ivar分配一个新的navcontroller实例,然后在释放它。然后,您可以在dealloc中释放并取消self.navcontroller ivar。如果您在应用程序中未使用自动释放和取消的概念,则不需要任何其他功能配合..int retVal=UIApplicationMain(argc,argv,nil,nil);在这一行的主文件中,我从应用程序的哪个点获得了sigabtf,您调用这个方法?哪种类是
self
?,它是
self
的超类?它的超类是UIViewController
[self presentViewController:temp animated:YES completion:nil];