Iphone-pushViewController在XCode 4.2中不工作



我正在制作一个在Xcode 3.2.5中创建的应用程序。我的应用程序在XCode 3.2.5中按预期工作,但由于一些内存问题,现在我使用XCode 4.2。

Xcode 4.2提供了一个将现有代码转换为ARC(自动引用计数)的工具。启用的代码。选择Edit -> Refactor……for me.

在我的代码中,我使用navigationController在UIbutton点击视图之间切换。UIButton以编程方式创建。我使用以下代码在button_click上推送视图控制器:

 -(void) button_click:(id)sender{
NSLog(@"button_clicked.....");
SecondView  *sv = [[SecondView alloc] initWithNibName:@"SecondView" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:sv animated:NO];
}
在button_click控制台显示消息button_clicked....。但是pushViewcontroller没有推送SecondView

pushViewController在XCode 3.2.5中工作,但在XCode 4.2按钮点击工作,但navigationController的pushViewController不工作。

我该如何修复它?

任何帮助都将是非常感激的。

提前感谢!

您是否尝试将RootViewController放入MainWindow.xib上的导航控制器中?

加上我的回答:

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {    
    [self.window makeKeyAndVisible];
    // create the MyView controller instance:
    MyViewController *controller = [[MyViewController alloc] initWithNibName:@"MyView" bundle:nil];
    // set the title that appears in the navigation bar:
    [controller.navigationItem setTitle:@"Main View"];
    // create the Navigation Controller instance:
    UINavigationController *newnav = [[UINavigationController alloc] initWithRootViewController:controller];
    // set the navController property:
    [self setNavController:newnav];
    // release both controllers:
    [newnav release];
    [controller release];
    // add the Navigation Controller's view to the window:
    [window addSubview:[navController view]];
    return YES;
}

[self.window setRootViewController:navigationController];
[self.window makeKeyAndVisible];

处理NavigationControllers的详细说明在这里

最新更新