在iPhone上点击按钮导航到新页面

时间:2012-06-16 11:01:25

标签: iphone animation navigation uibutton buttonclick

我是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

提前致谢!

2 个答案:

答案 0 :(得分:1)

基于你的应用程序视图,你不能推动控制器,最简单的事情是:

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

如果您想为它制作动画,我恐怕您要么自己实施动画,要么添加导航控制器来为您完成工作

答案 1 :(得分: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;
    }

我认为这会对你有所帮助。