0

我是 iPhone 开发人员的新手。

我想用动画导航到新页面,但我无法导航到新页面,

这是我的代码片段,

UIButton *Planbtn = (UIButton *)[self.view viewWithTag:1];
    [Planbtn addTarget:self action:@selector(btnClicked) forControlEvents:UIControlEventTouchUpInside];

..

-(void)btnClicked{
    NSLog(@"btnClicked");

    PlanPage *yourViewController = [[PlanPage alloc] initWithNibName:@"PlanPage" bundle:[NSBundle mainBundle]];
    [self.navigationController pushViewController:yourViewController animated:TRUE];
    [yourViewController release];
}

我可以btnClicked在我的日志中看到。

提前致谢 !

4

2 回答 2

1

作为基于您的应用程序视图,您无法推送控制器,最简单的做法是:

PlanPage *yourViewController = [[PlanPage alloc] initWithNibName:@"PlanPage" bundle:[NSBundle mainBundle]];
[self.view addSubView:yourViewController.view];
[yourViewController release];

如果你想动画,恐怕你要么自己实现动画,要么添加一个导航控制器来为你完成这项工作

于 2012-06-16T11:24:31.767 回答
1

将这些属性写入AppDelegate.h文件

@property (strong, nonatomic) YourFirstViewController *yourFirstController;
@property (nonatomic, retain) UINavigationController *navigationControl;

将此代码写入AppDelegate.m文件

  - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    {

        self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
        self.yourFirstViewController = [[YourFirstViewController alloc] initWithNibName:@"YourFirstViewController" bundle:nil]];
        navigationController = [[UINavigationController alloc] initWithRootViewController:self.yourFirstViewController];
        [self.window addSubview:[navigationController view]];
        [self.window makeKeyAndVisible];
        return YES;
    }

我想这会对你有所帮助。

于 2012-06-16T11:31:05.713 回答